因此,我正在研究一个程序,该程序可以在飞机上飞行时检测地面上不同形状和颜色的标志。它们都是未知的,但颜色会比周围的地形更加强烈,并且形状将是基本的几何形状。这包括正方形,三角形和圆,以及平行四边形和十字。不同颜色的某些物体的实时形状检测
我已经得到我的程序来检测形状,但它非常不稳定,并且不仅仅关注我想要的对象。它可以发现阴影和光线以及其他任何你能想象到的形状。这可能是因为我在整个框架上运行边缘检测而不是感兴趣的对象。
这里有我的想法来解决这个问题:
1)检测的颜色,然后找到周围的颜色(我不知道这是可能的)形状。
2)匹配形状与此人匹配数字的相同方式 - >http://blog.damiles.com/2008/11/basic-ocr-in-opencv/。如果实施到我的程序中,我发现与此方法相同的问题。我猜测它会尝试将所有内容与形状相匹配。
3)找到一种方法来裁剪高强度框架的一部分,然后对其进行形状识别。
我的问题是,我的下一步应该是什么?有没有办法让我的程序专注于感兴趣的对象而不是它看到的所有内容? (请记住,我希望最终记录对象的形状和颜色以及其内部的ascii字符。)
以下是我到目前为止的内容。
#include <iostream>
#include <cv.h>
#include <highgui.h>
using namespace std;
int main()
{
//show the original image
cvNamedWindow("Raw",CV_WINDOW_NORMAL);
CvCapture* capture = cvCaptureFromCAM(0);
IplImage* img;
while(1)
{
img = cvQueryFrame(capture);
//converting the original image into grayscale
IplImage* imgGrayScale = cvCreateImage(cvGetSize(img), 8, 1);
cvCvtColor(img,imgGrayScale,CV_BGR2GRAY);
//thresholding the grayscale image to get better results
cvThreshold(imgGrayScale,imgGrayScale,125,255,CV_THRESH_BINARY);
CvSeq* contours; //hold the pointer to a contour in the memory block
CvSeq* result; //hold sequence of points of a contour
CvMemStorage *storage = cvCreateMemStorage(0); //storage area for all contours
//finding all contours in the image
cvFindContours(imgGrayScale, storage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
//iterating through each contour
while(contours)
{
//obtain a sequence of points of contour, pointed by the variable 'contour'
result = cvApproxPoly(contours, sizeof(CvContour), storage, CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.02, 0);
//if there are 3 vertices in the contour(It should be a triangle)
if(result->total==3)
{
//iterating through each point
CvPoint *pt[3];
for(int i=0;i<3;i++){
pt[i] = (CvPoint*)cvGetSeqElem(result, i);
}
//////////drawing lines around the triangle
cvLine(img, *pt[0], *pt[1], cvScalar(255,0,0),4);
cvLine(img, *pt[1], *pt[2], cvScalar(255,0,0),4);
cvLine(img, *pt[2], *pt[0], cvScalar(255,0,0),4);
cout << "\nTriangle\n";
}
//if there are 4 vertices in the contour(It should be a quadrilateral)
else if(result->total==4)
{
//iterating through each point
CvPoint *pt[4];
for(int i=0;i<4;i++){
pt[i] = (CvPoint*)cvGetSeqElem(result, i);
}
//drawing lines around the quadrilateral
//cvLine(img, *pt[0], *pt[1], cvScalar(0,255,0),4);
//cvLine(img, *pt[1], *pt[2], cvScalar(0,255,0),4);
//cvLine(img, *pt[2], *pt[3], cvScalar(0,255,0),4);
//cvLine(img, *pt[3], *pt[0], cvScalar(0,255,0),4);
cout << "\nquadrilateral\n" ;
}
//if there are 7 vertices in the contour(It should be a heptagon)
else if(result->total ==7 )
{
//iterating through each point
CvPoint *pt[7];
for(int i=0;i<7;i++){
pt[i] = (CvPoint*)cvGetSeqElem(result, i);
}
//drawing lines around the heptagon
cvLine(img, *pt[0], *pt[1], cvScalar(0,0,255),4);
cvLine(img, *pt[1], *pt[2], cvScalar(0,0,255),4);
cvLine(img, *pt[2], *pt[3], cvScalar(0,0,255),4);
cvLine(img, *pt[3], *pt[4], cvScalar(0,0,255),4);
cvLine(img, *pt[4], *pt[5], cvScalar(0,0,255),4);
cvLine(img, *pt[5], *pt[6], cvScalar(0,0,255),4);
cvLine(img, *pt[6], *pt[0], cvScalar(0,0,255),4);
}
//obtain the next contour
contours = contours->h_next;
}
//show the image in which identified shapes are marked
cvNamedWindow("Tracked");
cvShowImage("Tracked",img);
char c = cvWaitKey(33); //wait for a key press
if(c==27)
{
//cleaning up
cvDestroyAllWindows();
cvReleaseMemStorage(&storage);
cvReleaseImage(&img);
cvReleaseImage(&imgGrayScale);
break;
}
}
return 0;
}
在此先感谢您的帮助!