Ask Your Question
0

How to Draw Crosshairs/Marked Axes

asked 2013-10-24 21:31:52 -0600

pistorinoj gravatar image

updated 2013-10-24 22:58:05 -0600

Is there some OpenCV routine that will draw crosshairs and/or mark the axes of an image in a Mat with tick marks? I have looked a bit and see no mention of one but it seems like something that a lot people probably do/want?

If there is no routine, any sample code would be appreciated. Also, is it faster to draw that for each image or make a template image and use that as a mask?

Thanks!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-10-25 04:16:47 -0600

updated 2013-10-25 04:21:33 -0600

I think it should be pretty easy to define a draw_crosshairs(Mat, Point(center_x,center_y))() function yourself. Steps that you should follow is:

  • Take the Mat element and locate the middle point.
  • Based on the middle coordinates draw 4 small lines of 3-4 pixels in the correct direction.
  • Then return the Mat element with the drawing on it.

There is no such functionality in OpenCV provided, because GUI interfacing is not the core buisness of OpenCV. The used visualisation is mainly for data validation, and openCV provides mostly functionality that runs in your processing layer under your GUI interface.

EDIT: The following command draws a crosshair in the middle of your screen. Reform this snippet for your purpose!

line((screenWidth/2)-20, screenHeight/2, (screenWidth/2)+20, screenHeight/2);  //crosshair horizontal
line(screenWidth/2, (screenHeight/2)-20, screenWidth/2, (screenHeight/2)+20);  //crosshair vertical
edit flag offensive delete link more

Comments

1

Thanks as always Steven.

Crosshairs/marked axes are something that many people using live camera feeds use/want. Here is a link to a video of someone using crosshairs with OpenCV in a way I imagine many people would be interested in. http://www.youtube.com/watch?v=emGQ80bTtBs

In any event, while I know that this is not the core of OpenCV's functionality,it might be something relatively simple to do that would address a desire/need.

pistorinoj gravatar imagepistorinoj ( 2013-10-25 09:16:37 -0600 )edit

He is actually doing exactly that line of code that I suggested, but than on subwindows and adding a circle in the center. I know people would like more interfacing tools, but since that is not the mail openCV focus, I am afraid that if you do not provided the functionality yourself, then it will not get into the codebase.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-10-28 03:51:23 -0600 )edit
2

answered 2017-03-16 07:23:36 -0600

enxdtw gravatar image

updated 2017-03-16 07:24:19 -0600

You can try the drawMarker function (red cross, 10 width, 1 line width)

cv::drawMarker(myimage, cv::Point(x, y),  cv::Scalar(0, 0, 255), MARKER_CROSS, 10, 1);
edit flag offensive delete link more

Comments

3

Post date is 2013

LBerger gravatar imageLBerger ( 2017-03-16 07:51:10 -0600 )edit

what header files should i include??

sonicmaster gravatar imagesonicmaster ( 2019-07-08 06:33:06 -0600 )edit

Question Tools

Stats

Asked: 2013-10-24 21:31:52 -0600

Seen: 19,474 times

Last updated: Mar 16 '17