Drawing fixed set of grid lines with OpenCV

断了今生、忘了曾经 提交于 2019-12-05 08:22:50

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); 
Gauranga

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