Drawing fixed set of grid lines with OpenCV

倖福魔咒の 提交于 2019-12-07 00:30:16

问题


Is it possible to draw user-defined grid lines with defined points at all intersections, against the output of the color detection sample in the OpenCV sample file? Basically, the webcam will need to be detecting human head and shoulders from above you. Then when a person is detected, I need the grid lines to be there so that I am able to know from which outermost grid (left shoulder), to the next outermost grid (right shoulder), in both x and y axis (forehead and back of head). Thereafter, these points have to be sent for operation of mechanical parts like actuator and valves.

I'm an entry level OpenCV user, with just beginner knowledge about working with C++. I am currently using OpenCV 2.1 on VS2008.


回答1:


It is difficult to tell what your problem really is.

If you just want to draw gridlines, there's no opencv function which does that. To plot lines in a grid, you can use cv::line in a loop, then draw the intersections with a nested loop.

// assume that mat.type=CV_8UC3

dist=50;

int width=mat.size().width;
int height=mat.size().height;

for(int i=0;i<height;i+=dist)
  cv::line(mat,Point(0,i),Point(width,i),cv::Scalar(255,255,255));

for(int i=0;i<width;i+=dist)
  cv::line(mat,Point(i,0),Point(i,height),cv::Scalar(255,255,255));

for(int i=0;i<width;i+=dist)
  for(int j=0;j<height;j+=dist)
    mat.at<cv::Vec3b>(i,j)=cv::Scalar(10,10,10); 



回答2:


For drawing a grid on image using OpenCV line function

Mat mat_img(image);
int stepSize = 65;

int width = mat_img.size().width;
int height = mat_img.size().height;

for (int i = 0; i<height; i += stepSize)
    cv::line(mat_img, Point(0, i), Point(width, i), cv::Scalar(0, 255, 255));

for (int i = 0; i<width; i += stepsSize)
    cv::line(mat_img, Point(i, 0), Point(i, height), cv::Scalar(255, 0, 255));


来源:https://stackoverflow.com/questions/12318239/drawing-fixed-set-of-grid-lines-with-opencv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!