1 | initial version |
@witek, @zerog 80, Hi I am beginner to opencv, I tried upto find mask.
My code goes here:
using namespace std; using namespace cv;
int main( ){ Mat src1; Mat src=imread("img.png",1); Mat thr,gray;
cvtColor(src,gray,CV_BGR2GRAY);
//adaptiveThreshold(gray,thr,255,ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY,99,7);
threshold(gray, thr, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU); namedWindow( "gryimage", 1 ); imshow( "gryimage", thr);
vector< vector <point> > contours; // Vector for storing contour vector< Vec4i > hierarchy;
int largest_contour_index=0; int largest_area=0; Mat mask(src.rows,src.cols,CV_8UC1,Scalar::all(0)); //create destination image
findContours( thr.clone(), contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE ); // Find the contours in the image for( int i = 0; i< contours.size(); i++ ) // iterate through each contour. { double a=contourArea( contours[i],false); // Find the area of contour if(a>largest_area){ largest_area=a; largest_contour_index=i; //Store the index of largest contour } }
vector<vector<point> >hull(1); convexHull(contours[largest_contour_index], hull[0],false,true ); drawContours( mask, hull, 0, Scalar(125), -1, 8, vector<vec4i>(), 0, Point() ); namedWindow( "mask Image", 1 ); imshow( "mask Image", mask ); waitKey(0); return 0;
}
using namespace std; using namespace cv;
int main( ){ Mat src1; Mat src=imread("img.png",1); Mat thr,gray;
cvtColor(src,gray,CV_BGR2GRAY);
//adaptiveThreshold(gray,thr,255,ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY,99,7);
threshold(gray, thr, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU); namedWindow( "gryimage", 1 ); imshow( "gryimage", thr);
vector< vector <point> > contours; // Vector for storing contour vector< Vec4i > hierarchy;
int largest_contour_index=0; int largest_area=0; Mat mask(src.rows,src.cols,CV_8UC1,Scalar::all(0)); //create destination image
findContours( thr.clone(), contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE ); // Find the contours in the image for( int i = 0; i< contours.size(); i++ ) { double a=contourArea( contours[i],false); // Find the area of contour if(a>largest_area){ largest_area=a; largest_contour_index=i; //Store the index of largest contour } }
vector<vector<point> >hull(1); convexHull(contours[largest_contour_index], hull[0],false,true ); drawContours( mask, hull, 0, Scalar(125), -1, 8, vector<vec4i>(), 0, Point() ); namedWindow( "mask Image", 1 ); imshow( "mask Image", mask ); waitKey(0); return 0;
My question is how to find angle by using corner points ?
2 | No.2 Revision |
@witek, @zerog 80, Hi I am beginner to opencv, I tried upto find mask.
My code goes here:
using namespace std; using namespace cv;
int main( ){ Mat src1; Mat src=imread("img.png",1); Mat thr,gray;
cvtColor(src,gray,CV_BGR2GRAY);
//adaptiveThreshold(gray,thr,255,ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY,99,7);
threshold(gray, thr, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU); namedWindow( "gryimage", 1 ); imshow( "gryimage", thr);
vector< vector <point> > contours; // Vector for storing contour vector< Vec4i > hierarchy;
int largest_contour_index=0; int largest_area=0; Mat mask(src.rows,src.cols,CV_8UC1,Scalar::all(0)); //create destination image
findContours( thr.clone(), contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE ); // Find the contours in the image for( int i = 0; i< contours.size(); i++ ) // iterate through each contour. { double a=contourArea( contours[i],false); // Find the area of contour if(a>largest_area){ largest_area=a; largest_contour_index=i; //Store the index of largest contour } }
vector<vector<point> >hull(1); convexHull(contours[largest_contour_index], hull[0],false,true ); drawContours( mask, hull, 0, Scalar(125), -1, 8, vector<vec4i>(), 0, Point() ); namedWindow( "mask Image", 1 ); imshow( "mask Image", mask ); waitKey(0); return 0;
}
using namespace std; using namespace cv;
int main( ){ Mat src1; Mat src=imread("img.png",1); Mat thr,gray;
cvtColor(src,gray,CV_BGR2GRAY);
//adaptiveThreshold(gray,thr,255,ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY,99,7);
threshold(gray, thr, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU); namedWindow( "gryimage", 1 ); imshow( "gryimage", thr);
vector< vector <point> > contours; // Vector for storing contour vector< Vec4i > hierarchy;
int largest_contour_index=0; int largest_area=0; Mat mask(src.rows,src.cols,CV_8UC1,Scalar::all(0)); //create destination image
findContours( thr.clone(), contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE ); // Find the contours in the image for( int i = 0; i< contours.size(); i++ ) { double a=contourArea( contours[i],false); // Find the area of contour if(a>largest_area){ largest_area=a; largest_contour_index=i; //Store the index of largest contour } }
vector<vector<point> >hull(1); convexHull(contours[largest_contour_index], hull[0],false,true ); drawContours( mask, hull, 0, Scalar(125), -1, 8, vector<vec4i>(), 0, Point() ); namedWindow( "mask Image", 1 ); imshow( "mask Image", mask ); waitKey(0); return 0;
My question is how to find angle by using corner points ?
3 | No.3 Revision |
@witek, @zerog 80,
@zerog80,
Hi
I am beginner to opencv, I tried upto find mask.
My code goes here:
using namespace std; using namespace cv;
int main( ){ Mat src1; Mat src=imread("img.png",1); Mat thr,gray;
cvtColor(src,gray,CV_BGR2GRAY);
//adaptiveThreshold(gray,thr,255,ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY,99,7);
threshold(gray, thr, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU); namedWindow( "gryimage", 1 ); imshow( "gryimage", thr);
vector< vector <point> > contours; // Vector for storing contour vector< Vec4i > hierarchy;
int largest_contour_index=0; int largest_area=0; Mat mask(src.rows,src.cols,CV_8UC1,Scalar::all(0)); //create destination image
findContours( thr.clone(), contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE ); // Find the contours in the image for( int i = 0; i< contours.size(); i++ ) // iterate through each contour. { double a=contourArea( contours[i],false); // Find the area of contour if(a>largest_area){ largest_area=a; largest_contour_index=i; //Store the index of largest contour } }
vector<vector<point> >hull(1); convexHull(contours[largest_contour_index], hull[0],false,true ); drawContours( mask, hull, 0, Scalar(125), -1, 8, vector<vec4i>(), 0, Point() ); namedWindow( "mask Image", 1 ); imshow( "mask Image", mask ); waitKey(0); return 0;
}
My question is how to find angle by using corner points ?