는 다음 코드opencv를 사용하여 볼록 결함을 찾는 방법은 무엇입니까?
#include"opencv2/opencv.hpp"
#include<iostream>
#include<math.h>
using namespace std;
using namespace cv;
main()
{
Mat img1,img2,sub,gray1,gray2,lab,ycbcr;
int v[3];
int row,col,i,j,t;
VideoCapture cap(0);
namedWindow("current");
cap>>img1;
sub=img1;
row=img1.rows;
col=img1.cols;
cvtColor(img1,gray1,CV_BGR2GRAY);
vector<vector<Point> > cont;
vector<Vec4i> hierarchy;
while (1) {
cap>>img2;
cvtColor(img2,gray2,CV_BGR2GRAY);
for(i=0;i<row;++i)
{
for (j=0; j<col; ++j)
{
if(abs(gray1.at<uchar>(i,j) - gray2.at<uchar>(i,j))>10)
{
sub.at<Vec3b>(i,j)[0] = img2.at<Vec3b>(i,j)[0];
sub.at<Vec3b>(i,j)[1] = img2.at<Vec3b>(i,j)[1];
sub.at<Vec3b>(i,j)[2] = img2.at<Vec3b>(i,j)[2];
}
else
{
sub.at<Vec3b>(i,j)[0]=0;
sub.at<Vec3b>(i,j)[1]=0;
sub.at<Vec3b>(i,j)[2]=0;
}
}
}
cvtColor(sub,ycbcr,CV_BGR2YCrCb);
inRange(ycbcr,Scalar(7,133,106),Scalar(255,178,129),ycbcr);
findContours(ycbcr,cont,hierarchy,CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
Scalar color = CV_RGB(255,255,255);
vector<vector<Point> > hullPoints(cont.size());
for( i = 0; i < cont.size(); i++)
convexHull(cont[i],hullPoints[i],false);
for(i = 0 ;i >= 0; i = hierarchy[i][0])
{
drawContours(ycbcr, cont, i, color,1, CV_AA, hierarchy);//for drawing contours
drawContours(ycbcr, hullPoints, i, color,2, CV_AA, hierarchy);//for drawing convex hull
}
flip(ycbcr,ycbcr,1);
imshow("current",ycbcr);
if(waitKey(33)=='q')
break;
img1=img2.clone();
}
}
이
어떻게 입력하는 convexHull..So에서 벡터 포인트 유형 결과가 어떻게 convexHull..cvConvexityDefects의 볼록 결함() const를 cvArr을 필요로 찾을 수 * arguments.But로 캐스팅 ..? 당신의 convexHull
계산
[이 질문에]보십시오 (http://stackoverflow.com/questions/6806637/convexity-defects-c-opencv) –
사용중인 OpenCV의 버전은 무엇입니까? AFAIK cvConvexHull 함수는 레거시이며 새 버전에서는 cvConvexHull2를 사용해야합니다. 또한 OpenCV에는 CvPoint, CvMat 및 CvSequense 유형이 있습니다. 왜 std 및 opencv 유형을 병합하는 대신 사용하지 않을까요? –
openCV 2.3을 사용하고 있습니다 –