Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to find convexity defects using opencv?
    text
    copied!<p>I have the following code</p> <pre><code> #include"opencv2/opencv.hpp" #include&lt;iostream&gt; #include&lt;math.h&gt; 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&gt;&gt;img1; sub=img1; row=img1.rows; col=img1.cols; cvtColor(img1,gray1,CV_BGR2GRAY); vector&lt;vector&lt;Point&gt; &gt; cont; vector&lt;Vec4i&gt; hierarchy; while (1) { cap&gt;&gt;img2; cvtColor(img2,gray2,CV_BGR2GRAY); for(i=0;i&lt;row;++i) { for (j=0; j&lt;col; ++j) { if(abs(gray1.at&lt;uchar&gt;(i,j) - gray2.at&lt;uchar&gt;(i,j))&gt;10) { sub.at&lt;Vec3b&gt;(i,j)[0] = img2.at&lt;Vec3b&gt;(i,j)[0]; sub.at&lt;Vec3b&gt;(i,j)[1] = img2.at&lt;Vec3b&gt;(i,j)[1]; sub.at&lt;Vec3b&gt;(i,j)[2] = img2.at&lt;Vec3b&gt;(i,j)[2]; } else { sub.at&lt;Vec3b&gt;(i,j)[0]=0; sub.at&lt;Vec3b&gt;(i,j)[1]=0; sub.at&lt;Vec3b&gt;(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&lt;vector&lt;Point&gt; &gt; hullPoints(cont.size()); for( i = 0; i &lt; cont.size(); i++ ) convexHull(cont[i],hullPoints[i],false); for(i = 0 ;i &gt;= 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(); } } </code></pre> <p>How to find the convexity defects in this convexHull..cvConvexityDefects() require const cvArr * as arguments.But i have vector point type result from convexHull..So how to type cast ..?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload