Created
February 5, 2016 14:52
-
-
Save ronalddas/28cf61fba25392c9bed1 to your computer and use it in GitHub Desktop.
Source code ( Still working)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<highgui/highgui.hpp> | |
#include<iostream> | |
#include<imgproc/imgproc.hpp> | |
#include<core/core.hpp> | |
using namespace cv; | |
using namespace std; | |
int main(int argc , char **argv) | |
{ | |
if( argc != 2) | |
{ | |
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl; | |
return -1; | |
} | |
int iLowH = 0; | |
int iHighH = 179; | |
int iLowS = 0; | |
int iHighS = 255; | |
int iLowV = 0; | |
int iHighV = 255; | |
namedWindow("Control",WINDOW_AUTOSIZE); | |
//Create trackbars in "Control" window | |
cvCreateTrackbar("LowH", "Control", &iLowH, 179); //Hue (0 - 179) | |
cvCreateTrackbar("HighH", "Control", &iHighH, 179); | |
cvCreateTrackbar("LowS", "Control", &iLowS, 255); //Saturation (0 - 255) | |
cvCreateTrackbar("HighS", "Control", &iHighS, 255); | |
cvCreateTrackbar("LowV", "Control", &iLowV, 255); //Value (0 - 255) | |
cvCreateTrackbar("HighV", "Control", &iHighV, 255); | |
//Nothing happened to the image after adding this! | |
Mat Image; | |
Image =imread(argv[1],CV_LOAD_IMAGE_UNCHANGED); | |
Mat ImageHSV; | |
cvtColor(Image , ImageHSV , COLOR_BGR2HSV); | |
namedWindow("Window",WINDOW_AUTOSIZE); | |
imshow("Window",ImageHSV); | |
Mat ImageThres; | |
//Problem is Here... The whole image is turning WHITE! | |
inRange(ImageHSV, Scalar(iLowH, iLowS, iLowV), Scalar(iHighH, iHighS, iHighV),ImageThres); | |
namedWindow("Window2",WINDOW_AUTOSIZE); | |
imshow("Window2",ImageThres); | |
//Morphological Opening | |
erode(ImageThres,ImageThres,getStructuringElement(MORPH_ELLIPSE,Size(5,5))); | |
dilate(ImageThres,ImageThres,getStructuringElement(MORPH_ELLIPSE,Size(5,5))); | |
//Morphological Closing | |
dilate(ImageThres,ImageThres,getStructuringElement(MORPH_ELLIPSE,Size(5,5))); | |
erode(ImageThres,ImageThres,getStructuringElement(MORPH_ELLIPSE,Size(5,5))); | |
namedWindow("Thresholded Image", WINDOW_AUTOSIZE); | |
namedWindow("Original",WINDOW_AUTOSIZE); | |
imshow("Thresholded Image", ImageThres); | |
imshow("Original",Image); | |
waitKey(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment