bmcv_image_threshold ==================== 图åƒé˜ˆå€¼åŒ–æ“作。 **接å£å½¢å¼ï¼š** .. code-block:: c bm_status_t bmcv_image_threshold( bm_handle_t handle, bm_image input, bm_image output, unsigned char thresh, unsigned char max_value, bm_thresh_type_t type); å…¶ä¸thresh类型如下: .. code-block:: c typedef enum { BM_THRESH_BINARY = 0, BM_THRESH_BINARY_INV, BM_THRESH_TRUNC, BM_THRESH_TOZERO, BM_THRESH_TOZERO_INV, BM_THRESH_TYPE_MAX } bm_thresh_type_t; å„个类型对应的具体公å¼å¦‚下: .. figure:: ./thresh_type.jpg :width: 899px :height: 454px :scale: 50% :align: center **å‚数说明:** * bm_handle_t handle 输入å‚数。 bm_handle å¥æŸ„。 * bm_image input 输入å‚数。输入图åƒçš„ bm_image,bm_image 需è¦å¤–部调用 bmcv_image_create 创建。image 内å˜å¯ä»¥ä½¿ç”¨ bm_image_alloc_dev_mem 或者 bm_image_copy_host_to_device æ¥å¼€è¾Ÿæ–°çš„内å˜ï¼Œæˆ–者使用 bmcv_image_attach æ¥ attach 已有的内å˜ã€‚ * bm_image output 输出å‚数。输出 bm_image,bm_image 需è¦å¤–部调用 bmcv_image_create 创建。image 内å˜å¯ä»¥é€šè¿‡ bm_image_alloc_dev_mem æ¥å¼€è¾Ÿæ–°çš„内å˜ï¼Œæˆ–者使用 bmcv_image_attach æ¥ attach 已有的内å˜ã€‚如果ä¸ä¸»åŠ¨åˆ†é…将在 api 内部进行自行分é…。 * unsigned char thresh 阈值。 * max_value 最大值。 * bm_thresh_type_t type 阈值化类型。 **返回值说明:** * BM_SUCCESS: æˆåŠŸ * 其他:失败 **æ ¼å¼æ”¯æŒï¼š** 该接å£ç›®å‰æ”¯æŒä»¥ä¸‹ image_format: +-----+------------------------+------------------------+ | num | input image_format | output image_format | +=====+========================+========================+ | 1 | FORMAT_BGR_PACKED | FORMAT_BGR_PACKED | +-----+------------------------+------------------------+ | 2 | FORMAT_BGR_PLANAR | FORMAT_BGR_PLANAR | +-----+------------------------+------------------------+ | 3 | FORMAT_RGB_PACKED | FORMAT_RGB_PACKED | +-----+------------------------+------------------------+ | 4 | FORMAT_RGB_PLANAR | FORMAT_RGB_PLANAR | +-----+------------------------+------------------------+ | 5 | FORMAT_RGBP_SEPARATE | FORMAT_RGBP_SEPARATE | +-----+------------------------+------------------------+ | 6 | FORMAT_BGRP_SEPARATE | FORMAT_BGRP_SEPARATE | +-----+------------------------+------------------------+ | 7 | FORMAT_GRAY | FORMAT_GRAY | +-----+------------------------+------------------------+ | 8 | FORMAT_YUV420P | FORMAT_YUV420P | +-----+------------------------+------------------------+ | 9 | FORMAT_YUV422P | FORMAT_YUV422P | +-----+------------------------+------------------------+ | 10 | FORMAT_YUV444P | FORMAT_YUV444P | +-----+------------------------+------------------------+ | 11 | FORMAT_NV12 | FORMAT_NV12 | +-----+------------------------+------------------------+ | 12 | FORMAT_NV21 | FORMAT_NV21 | +-----+------------------------+------------------------+ | 13 | FORMAT_NV16 | FORMAT_NV16 | +-----+------------------------+------------------------+ | 14 | FORMAT_NV61 | FORMAT_NV61 | +-----+------------------------+------------------------+ | 15 | FORMAT_NV24 | FORMAT_NV24 | +-----+------------------------+------------------------+ ç›®å‰æ”¯æŒä»¥ä¸‹ data_type: +-----+--------------------------------+ | num | data_type | +=====+================================+ | 1 | DATA_TYPE_EXT_1N_BYTE | +-----+--------------------------------+ **注æ„事项:** 1ã€åœ¨è°ƒç”¨è¯¥æŽ¥å£ä¹‹å‰å¿…须确ä¿è¾“入的 image 内å˜å·²ç»ç”³è¯·ã€‚ 2ã€input output çš„image_format以åŠdata_type必须相åŒã€‚ **代ç 示例:** .. code-block:: c int channel = 1; int width = 1920; int height = 1080; int dev_id = 0; bm_handle_t handle; bm_status_t dev_ret = bm_dev_request(&handle, dev_id); std::shared_ptr<unsigned char> src_ptr( new unsigned char[channel * width * height], std::default_delete<unsigned char[]>()); std::shared_ptr<unsigned char> res_ptr( new unsigned char[channel * width * height], std::default_delete<unsigned char[]>()); unsigned char * src_data = src_ptr.get(); unsigned char * res_data = res_ptr.get(); for (int i = 0; i < channel * width * height; i++) { src_data[i] = rand() % 255; } // calculate res bm_image input, output; bm_image_create(handle, height, width, FORMAT_GRAY, DATA_TYPE_EXT_1N_BYTE, &input); bm_image_alloc_dev_mem(input); bm_image_copy_host_to_device(input, (void **)&src_data); bm_image_create(handle, height, width, FORMAT_GRAY, DATA_TYPE_EXT_1N_BYTE, &output); bm_image_alloc_dev_mem(output); if (BM_SUCCESS != bmcv_image_threshold(handle, input, output, 200, 200, BM_THRESH_BINARY)) { std::cout << "bmcv thresh error !!!" << std::endl; bm_image_destroy(input); bm_image_destroy(output); bm_dev_free(handle); exit(-1); } bm_image_copy_device_to_host(output, (void **)&res_data); bm_image_destroy(input); bm_image_destroy(output); bm_dev_free(handle);