Ask Your Question
1

Drawing onto a transparent Mat

asked 2013-07-24 04:43:45 -0600

dredre gravatar image

updated 2013-07-24 04:46:43 -0600

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 draw on to the canvas but this doesn't seem to be working :

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

Any advice is greatly appreciated. Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-07-24 08:19:21 -0600

First of all, I suggest changing to the C++ API of OpenCV. The old C API is depricated and contains many reasons for bugs. Transparency can be done like this.

Then use the new Mat created as input to your drawing algorithm instead of the frame.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-07-24 04:43:45 -0600

Seen: 2,133 times

Last updated: Jul 24 '13