Items with no label
3335 Discussions

How to draw a circle, square, dot or line in the color PXCImage?

FApon
New Contributor I
1,198 Views

Due to the huge difficulties I had converting a CvMat image from OpenCV to PXCImage to do a mapping, I decided to try to draw the elements I need in the image myself (it works a circle, a square, a line, a dot), but the SDK intel has nothing for that except for a bounding box that must necessarily detect a person to track it and the function of accessing data from the image to modify it (it is not an option since I have not managed to make it work for the conversion).

I have the coordinates and the size, ie: I know in which pixel I have to graph the figures but I have not been able to find any way to draw them.

Thank you very much.

PS: I'm working with OpenCV, R200, intel SDK and C ++ in Visual Studio

0 Kudos
3 Replies
MartyG
Honored Contributor III
302 Views

OpenCV conversions usually involve converting PXCImage to .mat. I can understand the difficulty then of reversing the process and converting a .mat to PXCImage. Part of the problem may be that a RealSense stream is 16 bit resolution and the .mat becomes an 8-bit image when converted. So it would be hard to convert an 8-bit image to 16-bit because of the missing data - it would be like trying to improve the visibility of a 100x100 thumbnail image by scaling it up to 1000x1000.

It might be an easier reverse-conversion if you started with a 16-bit .mat image, perhaps. Google '16-bit .mat' for details.

I could not find shape drawing functions either, so I considered an alternate approach. This would be to set up a traditional mouse-controlled art painting script and assign control of the cursor and shape selection to your hands with RealSense instead of drawing with the mouse.

OpenCV does have drawing functions,

http://docs.opencv.org/3.2.0/dc/da5/tutorial_py_drawing_functions.html OpenCV: Drawing Functions in OpenCV

A problem though is that you are using the R200 camera, which can not track the joints of the hand and instead can only roughly follow the palm with 'Blob Tracking'. Or perhaps your project does not require camera-controlled drawing functions - just to capture an image that you can then draw over with the mouse?

0 Kudos
jb455
Valued Contributor II
302 Views

(Disclaimer: I've done all this in C# so it may be different for C++)

You can get the pointer to the image RGB buffer by doing

image.AcquireAccess(PXCMImage.Access.ACCESS_WRITE, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, out cData);

uint* colorPtr = (uint*)cData.planes[0].ToPointer();

Then you can loop through the pixels in the image and change the colour of the ones you're interested in by doing something like this:

for (int y = 0, k = 0; y < cheight; y++)

 

{

 

for (int x = 0; x < cwidth; x++, k++)

 

{

 

if (condition)

 

{

 

colorPtr[k] = 0x00000000; //turn pixel black

 

}

 

}

 

}

Then when you call image.ReleaseAccess(cData), the image buffer will be as you have modified it.

Alternatively, if there are bitmap drawing classes in C++ you may find it easier to use them. Get the RGB byte array (colorPtr), convert it to bitmap, then draw on it using System.Drawing or whatever then either update the PXCImage object by overwriting the colorPtr data or keep it as a bitmap to render from there.

MartyG
Honored Contributor III
302 Views

JB to the rescue again! Thanks muchly!

0 Kudos
Reply