-1

I just want to do convert a gray image to a binary image. But threshold function gives me a totaly black image as a binary image. I want to get dark gray object. What is wrong here?

Code:

Mat theFrame = imread("C:\\asdsss.png"); // opencv

Mat gray,binary;
cvtColor(theFrame, gray, CV_BGR2GRAY);
threshold(gray, binary, 150, 255, THRESH_BINARY); 
imwrite("result.jpg",binary);

İnput image: enter image description here

ffttyy
  • 853
  • 2
  • 19
  • 49

1 Answers1

0

The code works perfectly fine. I ran you exact code on the image provided. There is no issue with it. enter image description here

I got the following output by running your code. The only problem I can think of could be loading of image. Try to see your image using cv::imshow after loading it. Also try to convert your image into jpg format and then try loading it again. You can also try compiling and running the opencv thresholding sample.

Gaurav Raj
  • 699
  • 6
  • 21