我试图在某些样品中检测到品牌标识,但我无法获得任何可用的结果。使用cvBlobs
我发现所有相关的红色图像区域没有任何问题,但现在我必须了解哪些有ULKER徽标。我认为一个简单的 SURF alg。将完成这项工作(通过寻找其他类似计划的成功)
但结果远非好。此外,我尝试在进行任何处理之前应用cvCanny
以获得徽标的边缘表示并消除背景,但没有区别。你能帮忙告诉我我做错了什么吗?
logo,sample和代码
int find(IplImage* image, IplImage* object)
{
CvMemStorage* storage = cvCreateMemStorage(0);
cvNamedWindow("Object", 1);
cvNamedWindow("Object Correspond", 1);
static CvScalar colors[] =
{
{{0,0,255}},
{{0,128,255}},
{{0,255,255}},
{{0,255,0}},
{{255,128,0}},
{{255,255,0}},
{{255,0,0}},
{{255,0,255}},
{{255,255,255}}
};
CvSeq* objectKeypoints = 0, *objectDescriptors = 0;
CvSeq* imageKeypoints = 0, *imageDescriptors = 0;
int i;
CvSURFParams params = cvSURFParams(100, 0);
IplImage *objectGray = cvCreateImage(cvSize(object->width, object->height), object->depth,1);
IplImage *objectSobel = cvCreateImage(cvSize(object->width, object->height), IPL_DEPTH_16S,1);
cvCvtColor( object, objectGray, CV_BGR2GRAY );
cvCanny(objectGray,objectGray,50,20,3);
//cvConvertScale(objectSobel,objectGray);
IplImage *imageGray = cvCreateImage(cvSize(image->width, image->height), image->depth,1);
IplImage *imageSobel = cvCreateImage(cvSize(image->width, image->height), IPL_DEPTH_16S,1);
cvCvtColor( image, imageGray, CV_BGR2GRAY );
cvCanny(imageGray,imageGray,50,10,3);
//cvSobel(imageGray,imageSobel,dx,dy,ks);
//cvConvertScale(imageSobel,imageGray);
double tt = (double)cvGetTickCount();
cvExtractSURF( objectGray, 0, &objectKeypoints, &objectDescriptors, storage, params ,0);
printf("Object Descriptors: %d\n", objectDescriptors->total);
printf("Object Keypoints: %d\n", objectKeypoints->total);
cvExtractSURF( imageGray, 0, &imageKeypoints, &imageDescriptors, storage, params ,0);
printf("Image Descriptors: %d\n", imageDescriptors->total);
printf("Image Keypoints: %d\n", imageKeypoints->total);
tt = (double)cvGetTickCount() - tt;
printf( "Extraction time = %gms\n", tt/(cvGetTickFrequency()*1000.));
CvPoint src_corners[4] = {{0,0}, {objectGray->width,0}, {objectGray->width, objectGray->height}, {0, objectGray->height}};
CvPoint dst_corners[4];
if( locatePlanarObject( objectKeypoints, objectDescriptors, imageKeypoints,
imageDescriptors, src_corners, dst_corners ))
{
for( i = 0; i < 4; i++ )
{
CvPoint r1 = dst_corners[i%4];
CvPoint r2 = dst_corners[(i+1)%4];
cvLine( image, cvPoint(r1.x, r1.y ),
cvPoint(r2.x, r2.y ), colors[6] );
}
}
vector<int> ptpairs;
flannFindPairs( objectKeypoints, objectDescriptors, imageKeypoints, imageDescriptors, ptpairs );
for( i = 0; i < (int)ptpairs.size(); i += 2 )
{
CvSURFPoint* r1 = (CvSURFPoint*)cvGetSeqElem( objectKeypoints, ptpairs[i] );
CvSURFPoint* r2 = (CvSURFPoint*)cvGetSeqElem( imageKeypoints, ptpairs[i+1] );
CvPoint center;
int radius;
center.x = cvRound(r2->pt.x);
center.y = cvRound(r2->pt.y);
radius = cvRound(r2->size*1.2/9.*2);
cvCircle( image, center, radius, colors[0], 1, 8, 6 );
}
cvShowImage( "Object Correspond", image );
cvMoveWindow( "Object Correspond",400,400);
for( i = 0; i < objectKeypoints->total; i++ )
{
CvSURFPoint* r = (CvSURFPoint*)cvGetSeqElem( objectKeypoints, i );
CvPoint center;
int radius;
center.x = cvRound(r->pt.x);
center.y = cvRound(r->pt.y);
radius = cvRound(r->size*1.2/9.*2);
cvCircle( object, center, radius, colors[0], 1, 8, 6 );
}
cvShowImage( "Object", object );
cvWaitKey(0);
cvDestroyWindow("Object");
cvDestroyWindow("Object Correspond");
return 0;
}