Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

image description

@witek, @zerog 80, Hi I am beginner to opencv, I tried upto find mask.

My code goes here:

include "opencv2/highgui/highgui.hpp"

include "opencv2/imgproc/imgproc.hpp"

include <iostream>

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;

}

include "opencv2/highgui/highgui.hpp"

include "opencv2/imgproc/imgproc.hpp"

include <iostream>

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 ?

image description

@witek, @zerog 80, Hi I am beginner to opencv, I tried upto find mask.

My code goes here:

include "opencv2/highgui/highgui.hpp"

include "opencv2/imgproc/imgproc.hpp"

include <iostream>

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;

}

include "opencv2/highgui/highgui.hpp"

include "opencv2/imgproc/imgproc.hpp"

include <iostream>

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 ?

image description

@witek, @zerog 80, @zerog80, Hi I am beginner to opencv, I tried upto find mask.

My code goes here:

include "opencv2/highgui/highgui.hpp"

include "opencv2/imgproc/imgproc.hpp"

include <iostream>

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 ?