Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Drawing onto a transparent Mat

Hi,

I'm doing a colour tracking application that draws a line following that colour. You are probably quite familiar with the code, I followed an online tutorial :

//track yellow 
  IplImage* GetThresholdedImage1(IplImage* img)
{
// Convert the image into an HSV image


 IplImage* imgHSV = cvCreateImage(cvGetSize(img), 8, 3);
cvCvtColor(img, imgHSV, CV_BGR2HSV);
// Create new image to hold thresholded image
IplImage* imgThreshed = cvCreateImage(cvGetSize(img), 8, 1);
 cvInRangeS(imgHSV, cvScalar(20, 100, 100), cvScalar(30, 255, 255), imgThreshed); // apply threshold original
  cvReleaseImage(&imgHSV);
return imgThreshed;

}

IplImage *frame=0;
frame =cvQueryFrame(capture);
IplImage* imgYellowThresh1 = GetThresholdedImage1(frame);
//scribble lines on to frame 
    imgScribble =cvCreateImage(cvGetSize(frame),8,3);
    cvAdd(frame,imgScribble,frame);
    cvShowImage("video",frame);

So this draws a yellow line on the video from my webcam. What I want is to replace the video with a transparent background. Does anyone know how to create a transparent Mat and then draw onto it instead of the frame. I tried to add the frame on to a Mat but it keeps on erroring. Any advice is greatly appreciated. Thanks!

Drawing onto a transparent Mat

Hi,

I'm doing a colour tracking application that draws a line following that colour. You are probably quite familiar with the code, I followed an online tutorial :

//track yellow 
  IplImage* GetThresholdedImage1(IplImage* img)
{
// Convert the image into an HSV image


 IplImage* imgHSV = cvCreateImage(cvGetSize(img), 8, 3);
cvCvtColor(img, imgHSV, CV_BGR2HSV);
// Create new image to hold thresholded image
IplImage* imgThreshed = cvCreateImage(cvGetSize(img), 8, 1);
 cvInRangeS(imgHSV, cvScalar(20, 100, 100), cvScalar(30, 255, 255), imgThreshed); // apply threshold original
  cvReleaseImage(&imgHSV);
return imgThreshed;

}

IplImage *frame=0;
frame =cvQueryFrame(capture);
IplImage* imgYellowThresh1 = GetThresholdedImage1(frame);
//scribble lines on to frame 
    imgScribble =cvCreateImage(cvGetSize(frame),8,3);
    cvAdd(frame,imgScribble,frame);
    cvShowImage("video",frame);

So this draws a yellow line on the video from my webcam. What I want is to replace the video with a transparent background. Does anyone know how to create a transparent Mat and then draw onto it instead of the frame. I tried to add the frame draw on to a Mat the canvas but it keeps on erroring. this doesn't seem to be working :

 IplImage* imgYellowThresh1 = GetThresholdedImage1(canvas);
cvAdd(canvas,imgScribble,canvas);

Any advice is greatly appreciated. Thanks!