Quantcast
Viewing all articles
Browse latest Browse all 41027

Create mask to select the black area

I have a black area around my image and i want to create a mask using OpenCv C++ that select just this black area so that i can paint it later. how Can i do that with out affect the image it self. I try to converted to grayscale image and then using threshold to converted it to binary, but its affect my image since its contain black pixels. ![image description](/upfiles/1445931637431547.jpg) This is the code i used to find the biggest contoure #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp"" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/photo/photo.hpp" #include using namespace cv; using namespace std; int main( ) { Mat src; src = imread("pano1.jpg", CV_LOAD_IMAGE_COLOR); Mat gray; cvtColor(src, gray, CV_BGR2GRAY); threshold(gray, gray,30, 255,THRESH_BINARY_INV); //Threshold the gray imshow("gray",gray); int largest_area=0; int largest_contour_index=0; Rect bounding_rect; vector> contours; // Vector for storing contour vector hierarchy; findContours( gray, contours, hierarchy,CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE ); // iterate through each contour. for( int i = 0; i< contours.size(); i++ ) { // Find the area of contour double a=contourArea( contours[i],false); if(a>largest_area){ largest_area=a;cout<

Viewing all articles
Browse latest Browse all 41027


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>