Advertisement
Guest User

Untitled

a guest
Nov 13th, 2013
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <opencv2/core/core.hpp>
  2. #include <opencv2/highgui/highgui.hpp>
  3. #include <opencv2/imgproc/imgproc.hpp>
  4.  
  5. using namespace cv;
  6. using namespace std;
  7.  
  8. int main(){
  9.     Mat img=imread("frame44.jpg");
  10.  
  11.     //Mat blurred;
  12.     //blur(img,blurred,cv::Size(5,5));
  13.  
  14.     Mat hsv;
  15.     cvtColor(img,hsv,CV_BGR2HSV);  
  16.  
  17.    
  18.  
  19.     Mat binary;
  20.     inRange(hsv,Scalar(23,0,250),Scalar(100,150,255),binary);
  21.    
  22.    
  23.    
  24.     //inRange(src, Scalar(lowBlue, lowGreen, lowRed), Scalar(highBlue, highGreen, highRed), redColorOnly);
  25.  
  26.     vector<vector<Point>> contours;
  27.     findContours(binary.clone(),contours,RETR_EXTERNAL,CHAIN_APPROX_SIMPLE);
  28.  
  29.     Mat dst= Mat::zeros(img.size(),img.type());
  30.     drawContours(dst,contours,-1,Scalar::all(255),CV_FILLED);
  31.  
  32.     dst &=img;
  33.  
  34.     namedWindow("Original",CV_WINDOW_AUTOSIZE);
  35.     imshow("Original",img);
  36.     namedWindow("HSV result",CV_WINDOW_NORMAL);
  37.     imshow("HSV result",hsv);
  38.     namedWindow("binary result",CV_WINDOW_NORMAL);
  39.     imshow("binary result",binary);
  40.     namedWindow("dst",CV_WINDOW_NORMAL);
  41.     imshow("dst",dst);
  42.  
  43.     waitKey(0);
  44.     return 1;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement