1

I'm writing code with visual c++ using opencv and qt libraries. I'm trying to apply a threshold to an iplImage and displaying it but I've some problems: when I pass my iplImage to cvThreshold function (with an hypothetical threshold of 0) doesn't return a white image and I don't know why. To display the function I'm using emit:

uchar *qimout=new uchar[sImg];
            IplImage *greyImage=cvCreateImage(cvSize(wImg,hImg),IPL_DEPTH_8U,1);
            cvThreshold(currentImage,greyImage,0,255,cv::THRESH_BINARY);
            greyImage->imageData = (char*)qimout;
            emit renderImage(QImage(qimout,wImg,hImg,QImage::Format_Indexed8));

Can someone help me? Thanks in advance.

tiavec88
  • 345
  • 1
  • 4
  • 12

1 Answers1

0

I think this is related to this post Convert RGB to Black & White in OpenCV

     // C
        IplImage *im_rgb  = cvLoadImage("image.jpg");
        IplImage *im_gray = cvCreateImage(cvGetSize(im_rgb),IPL_DEPTH_8U,1);
        cvCvtColor(im_rgb,im_gray,CV_RGB2GRAY);

        // C++
        Mat im_rgb  = imread("image.jpg");
        Mat im_gray;
        cvtColor(im_rgb,im_gray,CV_RGB2GRAY);
        // C
IplImage* im_bw = cvCreateImage(cvGetSize(im_gray),IPL_DEPTH_8U,1);
cvThreshold(im_gray, im_bw, 128, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);

// C++
Mat img_bw = im_gray > 128;
Community
  • 1
  • 1
thehilmisu
  • 342
  • 1
  • 5
  • 13