Ask Your Question

Revision history [back]

Try this code: Just make sure the image given to imread exists.

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char** argv)
{
    cv::Mat img = cv::imread("dm.jpg");
    cv::Point p1, p2;
    for(int r = 4; r < img.rows; r+=5){
        for(int c = 4; c < img.cols; c +=5){
            //vLines
            p1.x = c;
            p1.y = 0;
            p2.x = c;
            p2.y = img.rows;
            cv::line(img, p1, p2, cv::Scalar(255, 255, 255));
            //hLines
            p1.x = 0;
            p1.y = r;
            p2.x = img.cols;
            p2.y = r;
            cv::line(img, p1, p2, cv::Scalar(255, 255, 255));
        }
    }
    std::string win_name = "MyWindow";
    cv::namedWindow(win_name, CV_WINDOW_AUTOSIZE);
    cv::imshow(win_name, img);
    cv::waitKey();
}