Created
November 29, 2016 23:55
-
-
Save EduardoLezano/1a65f1c1a22da71c1305d8d5ed044114 to your computer and use it in GitHub Desktop.
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 <stdio.h> | |
#include <iostream> | |
#include <stdlib.h> | |
#include <opencv2/core/core.hpp> | |
#include <opencv2/highgui/highgui.hpp> | |
#include "opencv2/imgproc/imgproc.hpp" | |
#include <opencv/cv.h> | |
using namespace cv; | |
using namespace std; | |
Mat src,scr_gris,dst,dst2; | |
int TipoDeUmbral = 0; | |
int maxUmbral = 6; | |
int thresholdValue = 0; | |
int thresholdValue2 = 255; | |
int maxThreshold = 255; | |
int maxBinaryValue = 255; | |
void CalcularUmbral(int,void*); | |
int main(int argc, char *argv[]){ | |
src = imread("/home/eduardo/Imágenes/GrayScale.png",1); | |
if(!src.data){ | |
cout<<"NO SE CARGO LA IMAGEN"<<endl; | |
} | |
cvtColor(src,scr_gris,CV_BGR2GRAY); | |
namedWindow("Umbral",WINDOW_AUTOSIZE); | |
createTrackbar("TipoDeUmbral", "Umbral",&TipoDeUmbral, maxUmbral, CalcularUmbral); | |
createTrackbar("ThresholValue","Umbral",&thresholdValue,maxThreshold,CalcularUmbral); | |
createTrackbar("ThresholValue2","Umbral",&thresholdValue2,maxThreshold,CalcularUmbral); | |
CalcularUmbral(0,0); | |
int c; | |
while (true) { | |
CalcularUmbral(0,0); | |
c = waitKey(20); | |
if((char)c == 27){ | |
break; | |
} | |
} | |
} | |
void CalcularUmbral(int,void*){ | |
switch (TipoDeUmbral) { | |
case 0: | |
threshold(scr_gris, dst, thresholdValue, maxBinaryValue,CV_THRESH_BINARY); | |
break; | |
case 1: | |
threshold(scr_gris, dst, thresholdValue, maxBinaryValue,CV_THRESH_BINARY_INV); | |
break; | |
case 2: | |
threshold(scr_gris, dst, thresholdValue, maxBinaryValue,CV_THRESH_TRUNC); | |
break; | |
case 3: | |
threshold(scr_gris, dst, thresholdValue, maxBinaryValue,CV_THRESH_TOZERO); | |
break; | |
case 4: | |
threshold(scr_gris, dst, thresholdValue, maxBinaryValue,CV_THRESH_TOZERO_INV); | |
break; | |
case 5: | |
threshold(scr_gris, dst, thresholdValue, maxBinaryValue,CV_THRESH_BINARY); | |
threshold(scr_gris, dst2, thresholdValue2, maxBinaryValue,CV_THRESH_BINARY_INV); | |
dst &= dst2; | |
break; | |
case 6: | |
threshold(scr_gris, dst, 0, maxBinaryValue,CV_THRESH_BINARY|CV_THRESH_OTSU); | |
break; | |
default: | |
break; | |
} | |
imshow("Umbral",dst); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment