This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DM642使用VLIB的函数 VLIB_createConnectedComponentsList()来处理连通域,总也不对,这是为啥???



下面是代码和图片
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**/
   
} 

一下是printf输出的结果:

+---------------------------------------+
| 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)

如果是以8邻域处理,应该只有两个连通域,但是现在输出的结果根本不对啊,求大神指教!!!