Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello, I have tested your solution by this code :

Mat src;
if (argc > 1)
{
    cout << "image : " << argv[1] << endl;
    src = imread(argv[1], 1);//read the image in parameter
}
else
    src = imread(appDir + "\\image.jpg",1);
Mat src_gray, binary, blurred;
cv::imwrite(appDir + "\\color.jpg", src);
Mat resized;
resize(src, resized, Size(0,0), 0.3, 0.3);
cv::imwrite(appDir + "\\resized.jpg", resized);
cvtColor(resized, src_gray, CV_BGR2GRAY);//converts the image into gray
cv::imwrite(appDir + "\\src_gray.jpg", src_gray);
Mat inverted;
bitwise_not(src_gray, inverted);
medianBlur(inverted, blurred, 9);//blur the image to eliminate noise
cv::imwrite(appDir + "\\blur.jpg", blurred);
threshold(blurred, binary,02, 255, THRESH_BINARY | THRESH_OTSU);
//threshold(blurred, binary, 50, 255, THRESH_BINARY);
cv::imwrite(appDir + "\\binaryOtsu.jpg", binary);

but I get this image : http://sylvain-ard.fr/temp/binaryOtsu.jpg which is very different from yours and not good, can you explain what I forget, I use OpenCV 3.4.6 Thank you Best regards

Hello, I have tested your solution by this code :

Mat src;
if (argc > 1)
{
    cout << "image : " << argv[1] << endl;
    src = imread(argv[1], 1);//read the image in parameter
}
else
    src = imread(appDir + "\\image.jpg",1);
Mat src_gray, binary, blurred;
cv::imwrite(appDir + "\\color.jpg", src);
Mat resized;
resize(src, resized, Size(0,0), 0.3, 0.3);
cv::imwrite(appDir + "\\resized.jpg", resized);
cvtColor(resized, src_gray, CV_BGR2GRAY);//converts the image into gray
cv::imwrite(appDir + "\\src_gray.jpg", src_gray);
Mat inverted;
bitwise_not(src_gray, inverted);
medianBlur(inverted, blurred, 9);//blur the image to eliminate noise
cv::imwrite(appDir + "\\blur.jpg", blurred);
threshold(blurred, binary,02, binary,127, 255, THRESH_BINARY | THRESH_OTSU);
//threshold(blurred, binary, 50, 255, THRESH_BINARY);
cv::imwrite(appDir + "\\binaryOtsu.jpg", binary);

but I get this image : http://sylvain-ard.fr/temp/binaryOtsu.jpg which is very different from yours and not good, can you explain what I forget, I use OpenCV 3.4.6 Thank you Best regards