- void VLIB_ConnectedComponents()
- {
- Uint8* imgData;
- Uint32* imgInData;
- Uint8 *outputimg;
- int i;
- int maxBytesRequired;
- int bytesRecommended;
- int status;
- int sizeOfCCHandle;
-
- int area;
- int left;
- int right;
- int top;
- int bottom;
- int xsum;
- int ysum;
- int imgwidth,imgheight;
- VLIB_CC vlibBlob;
- void *pBuf;
- VLIB_CCHandle* handle;
- int numCCs;
-
- char* fileDir = "F:\\DSP\\VLIB_V_2_1\\VLIB_V_2_1\\examples\\DM642\\y.bmp";
-
- imgheight = get_image_height(fileDir);
- imgwidth = get_image_width(fileDir);
-
- imgData = (Uint8*)malloc(sizeof(Uint8)*imgheight*imgwidth);
- imgInData = (Uint32*)malloc(sizeof(Uint32)*imgheight*imgwidth/32);
- outputimg = (Uint8*)malloc(sizeof(unsigned char)*imgheight*imgwidth);
- get_image_pointer(fileDir,imgData,imgwidth*imgheight);
-
- Create32BitPackedBinImage( imgData,
- imgwidth,
- imgheight,
- imgInData,
- 240);
-
- VLIB_calcConnectedComponentsMaxBufferSize(imgwidth,imgheight,MINBLOBAREA,&maxBytesRequired);
-
- bytesRecommended = maxBytesRequired ;
-
- sizeOfCCHandle = VLIB_GetSizeOfCCHandle();
- handle = (VLIB_CCHandle*)malloc(sizeOfCCHandle);//Uint8 handle[sizeOfCCHandle]
- pBuf = (void*)malloc(bytesRecommended);
-
- // memset(handle,0,sizeOfCCHandle);
- // memset(pBuf,0,bytesRecommended);
-
- status = VLIB_initConnectedComponentsList(handle, (void *)pBuf, bytesRecommended);
-
- status = VLIB_createConnectedComponentsList(handle,imgwidth,imgheight,(int*)imgInData,MINBLOBAREA,1);//1为8邻域操作
- if (status == VLIB_WARNING_LOW_MEMORY)
- {
- printf("\nConnected Components low memory warning!!! Buffer within 1kbyte of allocation!!!\n");
- }
- else if (status != VLIB_NO_ERROR)
- {
- printf("\nCreation of Connected Components failed!!!\n");
- }
- fflush(stdout);
-
- VLIB_getNumCCs(handle, &numCCs);
- // **test**
- //Report CC Features
- for (i=0; i < numCCs; i++)
- {
- VLIB_getCCFeatures(handle, &vlibBlob, i);
- left = vlibBlob.xmin;
- right = vlibBlob.xmax;
- top = vlibBlob.ymin;
- bottom = vlibBlob.ymax;
- xsum = vlibBlob.xsum;
- ysum = vlibBlob.ysum;
- area = vlibBlob.area;
-
- printf("Connected component #%d:\n", i+1);
- printf("Pixel Area : %d\n", area);
- printf("Bounding Box: left = %2d, right = %2d, top = %2d, bottom = %2d\n",left, right, top, bottom);
- // printf(" Horz. Sum : %d\n", xsum);
- // printf(" Vert. Sum : %d\n", ysum);
- printf("Centroid : (%4.1f,%4.1f)\n\n", (float)xsum/area, (float)ysum/area);
- // Unpack32BitPackedBinImage(imgInData,
- // imgwidth,
- // imgheight,
- // outputimg);
-
- // fflush(stdout);
- // if(area >= 4000)
- // {
-
- // draw_label_square(imgData,left,top,right,bottom,255);
- // draw_cross_5X5(disRGBbuffer,x_l,y_l,yellow);
- // draw_labelXXX(disRGBbuffer, left,top*2,yellow); //
- // draw_labelXXX(disRGBbuffer, right,top*2,yellow); //
- // draw_labelXXX(disRGBbuffer, left,bottom*2,yellow); //
- // draw_labelXXX(disRGBbuffer, right,bottom*2,yellow); //
- // }
-
- }
- // draw_label_square(imgData,left,top,right,bottom,yellow);
- free(pBuf);
- free(handle);
- /**test**/
-
- }