DM642使用VLIB的函数 VLIB_createConnectedComponentsList()来处理连通域

[复制链接]
3201|5
 楼主| yiyieqiu 发表于 2015-9-12 10:42 | 显示全部楼层 |阅读模式
以下是代码和图片,结果
  1. void VLIB_ConnectedComponents()
  2. {


  3.     Uint8* imgData;
  4.         Uint32* imgInData;
  5.         Uint8 *outputimg;
  6.     int i;
  7.         int maxBytesRequired;
  8.         int bytesRecommended;
  9.     int status;
  10.     int sizeOfCCHandle;
  11.        
  12.         int area;
  13.     int left;
  14.     int right;
  15.     int top;
  16.     int bottom;
  17.         int xsum;
  18.         int ysum;
  19.         int imgwidth,imgheight;
  20.     VLIB_CC vlibBlob;
  21.         void *pBuf;
  22.     VLIB_CCHandle* handle;
  23.     int numCCs;
  24.        
  25.         char* fileDir = "F:\\DSP\\VLIB_V_2_1\\VLIB_V_2_1\\examples\\DM642\\y.bmp";
  26.    
  27.     imgheight = get_image_height(fileDir);
  28.         imgwidth = get_image_width(fileDir);
  29.        
  30.         imgData = (Uint8*)malloc(sizeof(Uint8)*imgheight*imgwidth);
  31.         imgInData = (Uint32*)malloc(sizeof(Uint32)*imgheight*imgwidth/32);
  32.         outputimg = (Uint8*)malloc(sizeof(unsigned char)*imgheight*imgwidth);

  33.         get_image_pointer(fileDir,imgData,imgwidth*imgheight);
  34.          
  35.     Create32BitPackedBinImage(  imgData,
  36.                                 imgwidth,
  37.                                 imgheight,
  38.                                 imgInData,
  39.                                 240);
  40.        
  41.         VLIB_calcConnectedComponentsMaxBufferSize(imgwidth,imgheight,MINBLOBAREA,&maxBytesRequired);

  42.         bytesRecommended = maxBytesRequired ;
  43.        
  44.         sizeOfCCHandle =  VLIB_GetSizeOfCCHandle();  
  45.         handle = (VLIB_CCHandle*)malloc(sizeOfCCHandle);//Uint8 handle[sizeOfCCHandle]
  46.         pBuf = (void*)malloc(bytesRecommended);
  47.        
  48. //        memset(handle,0,sizeOfCCHandle);
  49. //        memset(pBuf,0,bytesRecommended);
  50.        
  51.         status = VLIB_initConnectedComponentsList(handle, (void *)pBuf, bytesRecommended);
  52.           
  53.         status = VLIB_createConnectedComponentsList(handle,imgwidth,imgheight,(int*)imgInData,MINBLOBAREA,1);//1为8邻域操作

  54.             if (status == VLIB_WARNING_LOW_MEMORY)
  55.                 {
  56.                         printf("\nConnected Components low memory warning!!! Buffer within 1kbyte of allocation!!!\n");
  57.                 }
  58.                 else if (status != VLIB_NO_ERROR)
  59.                 {
  60.                         printf("\nCreation of Connected Components failed!!!\n");
  61.                 }

  62.             fflush(stdout);
  63.             
  64.             VLIB_getNumCCs(handle, &numCCs);


  65.             // **test**  
  66.             //Report CC Features
  67.             for (i=0; i < numCCs; i++)
  68.             {
  69.                 VLIB_getCCFeatures(handle, &vlibBlob, i);

  70.                         left    = vlibBlob.xmin;
  71.                         right   = vlibBlob.xmax;
  72.                         top     = vlibBlob.ymin;
  73.                         bottom  = vlibBlob.ymax;
  74.                 xsum    = vlibBlob.xsum;
  75.                 ysum    = vlibBlob.ysum;
  76.                 area    = vlibBlob.area;
  77.            
  78.                 printf("Connected component #%d:\n", i+1);
  79.                 printf("Pixel Area  : %d\n", area);
  80.                 printf("Bounding Box: left = %2d, right = %2d, top = %2d, bottom = %2d\n",left, right, top, bottom);
  81. //                printf("  Horz. Sum   : %d\n", xsum);
  82. //                printf("  Vert. Sum   : %d\n", ysum);
  83.                         printf("Centroid    : (%4.1f,%4.1f)\n\n", (float)xsum/area, (float)ysum/area);

  84. //                        Unpack32BitPackedBinImage(imgInData,
  85. //                                      imgwidth,
  86. //                                      imgheight,
  87. //                                      outputimg);
  88.                        
  89. //                        fflush(stdout);
  90. //                        if(area >= 4000)
  91. //                        {
  92.                        
  93. //                        draw_label_square(imgData,left,top,right,bottom,255);

  94. //               draw_cross_5X5(disRGBbuffer,x_l,y_l,yellow);
  95. //                           draw_labelXXX(disRGBbuffer, left,top*2,yellow);      //   
  96. //                           draw_labelXXX(disRGBbuffer, right,top*2,yellow);     //
  97. //                           draw_labelXXX(disRGBbuffer, left,bottom*2,yellow);   //
  98. //                           draw_labelXXX(disRGBbuffer, right,bottom*2,yellow);  //

  99. //            }
  100.             
  101.             }

  102. //        draw_label_square(imgData,left,top,right,bottom,yellow);

  103.                 free(pBuf);
  104.                 free(handle);
  105.                 /**test**/
  106.    
  107. }


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| yiyieqiu 发表于 2015-9-12 10:43 | 显示全部楼层
这是输出的结果:

+---------------------------------------+
| TESTING: Connected Components         |
+---------------------------------------+

d倫bc孭ixel Area  : 276
Bounding Box: left = 62, right = 285, top = 10, bottom = 16
Centroid    : (183.6,13.2)

Connected component #2:
Pixel Area  : 348
Bounding Box: left =  0, right = 285, top = 16, bottom = 25
Centroid    : (152.2,21.2)

Connected component #3:
Pixel Area  : 348
Bounding Box: left =  0, right = 285, top = 25, bottom = 34
Centroid    : (152.2,30.2)

Connected component #4:
Pixel Area  : 348
Bounding Box: left =  0, right = 285, top = 34, bottom = 43
Centroid    : (152.2,39.2)

Connected component #5:
Pixel Area  : 538
Bounding Box: left =  0, right = 285, top = 38, bottom = 46
Centroid    : (144.6,42.3)

Connected component #6:
Pixel Area  : 216
Bounding Box: left =  0, right = 193, top = 43, bottom = 49
Centroid    : (95.5,46.5)

Connected component #7:
Pixel Area  : 540
Bounding Box: left =  0, right = 285, top = 46, bottom = 55
Centroid    : (144.1,51.3)

Connected component #8:
Pixel Area  : 504
Bounding Box: left =  6, right = 285, top = 51, bottom = 58
Centroid    : (153.3,54.6)

Connected component #9:
Pixel Area  : 1324
Bounding Box: left =  0, right = 285, top = 55, bottom = 68
Centroid    : (153.3,62.6)

Connected component #10:
Pixel Area  : 1176
Bounding Box: left =  0, right = 285, top = 66, bottom = 77
Centroid    : (141.8,72.2)

Connected component #11:
Pixel Area  : 1176
Bounding Box: left =  0, right = 285, top = 75, bottom = 86
Centroid    : (141.8,81.2)

Connected component #12:
Pixel Area  : 1288
Bounding Box: left =  0, right = 285, top = 84, bottom = 96
Centroid    : (147.1,90.5)

Connected component #13:
Pixel Area  : 1398
Bounding Box: left =  0, right = 285, top = 93, bottom = 105
Centroid    : (142.8,99.3)

Connected component #14:
Pixel Area  : 1398
Bounding Box: left =  0, right = 285, top = 102, bottom = 114
Centroid    : (142.8,108.3)

Connected component #15:
Pixel Area  : 1226
Bounding Box: left =  0, right = 285, top = 111, bottom = 122
Centroid    : (136.0,116.9)

Connected component #16:
Pixel Area  : 1044
Bounding Box: left =  0, right = 285, top = 120, bottom = 131
Centroid    : (139.5,126.0)

Connected component #17:
Pixel Area  : 786
Bounding Box: left =  0, right = 285, top = 129, bottom = 140
Centroid    : (132.2,134.9)

结果不对啊,求大神指点啊
 楼主| yiyieqiu 发表于 2015-9-12 10:45 | 显示全部楼层
这个图片,若果使用8邻域扫描,只有两个连通域,4邻域扫描,有三个连通域,这是为啥,结果完全不正确
还有我的图片尺寸是286*141
kangbidz 发表于 2015-9-12 11:23 | 显示全部楼层
好吧,我看不懂
zhangmangui 发表于 2015-9-12 15:34 | 显示全部楼层
不懂     帮顶
dalianmaof 发表于 2015-12-23 10:53 | 显示全部楼层
请问你是怎么读取本地BMP图像的,get_image_pointer这个函数是自己写的吗》可以分享下吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5

主题

15

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部