Drawing fixed set of grid lines with OpenCV

11,889

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); 
Share:
11,889
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    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.