How Can I display HSV output in a picture box?

asked 2017-04-19 01:19:39 -0500

Mehdi.Am gravatar image

updated 2017-04-19 01:55:00 -0500

Dear friends

Recently, I tried to display an output which is converted to HSV, into a picture box.
unfortunately nothing is shown in picturebox but when I use none-HSV image (BGR) it will be displayed!

here is part of my code:

IplImage returnOutputImage()
{
    Mat dst;

    //Brightness Contrast Calibration
    double dContrast = trackBar2->Value / 50.0;
    int iBrightness = trackBar3->Value - 50;

    //HSV Calibration
     int iLowH = 170; //trackBarHueMin->Value; 
     int iHighH = 179;//trackBarHueMax->Value;

     int iLowS = 150; //trackBarSatMin->Value; 
     int iHighS = 255;//trackBarSatMax->Value;

     int iLowV = 60; //trackBarValMin->Value;
     int iHighV =  255;//trackBarValMax->Value;


    cv::Mat s = cv::cvarrToMat(ip_frame);
    s.convertTo(dst, -1, dContrast,iBrightness); 

    Mat imgHSV,imgThresholded,dstnEW;
    cvtColor(dst, imgHSV, CV_BGR2HSV);
    inRange(imgHSV, Scalar(iLowH, iLowS, iLowV), Scalar(iHighH, iHighS, iHighV), imgThresholded); //Threshold the image

    //cvtColor(imgThresholded, dstnEW, CV_HSV2RGB_FULL);

    IplImage dstNew = imgThresholded;
    return dstNew;
}

finally,here I wanna show this image:

pictureBox2->Image  = gcnew System::Drawing::Bitmap(ip_frame->width,ip_frame->height,ip_frame->widthStep,System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) returnOutputImage().imageData);
edit retag flag offensive close merge delete

Comments

You are using old and deprecated C-API ... is there a reason for doing so? Why return an IplImage instead of a Mat? Also make sure you are scaling your image data. You are pushing it to a RGB color plane and thus your data might not be in the 0-255 pixel range.

StevenPuttemans gravatar imageStevenPuttemans ( 2017-04-19 04:51:12 -0500 )edit