我写了以下代码
#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,0,0);
for(int i1 = 0 ;i1 >= 0; i1 = hierarchy[i1][0] )
drawContours( ycbcr, cont, i1, color,2, CV_AA, hierarchy );
vector<Point2f > hullPoints;
// convexHull(Mat(cont),hullPoints,false);
imshow("current",ycbcr);
一个 if(waitKey(33)=='q') 中断;img1=img2.clone(); }
}
1.)为什么轮廓没有以红色显示,尽管我通过 CV_RGB(255,0,0) 指定了它。2.)当我取消注释线 convexHull(Mat(cont),hullPoints,false); ,程序显示运行时错误。为什么会发生。谁能告诉我convexHull()的确切格式及其参数的含义