C++ line() function not drawing anything

cv::Mat annotated_frame = m_detector.annotate();
cv::line(annotated_frame, Point(0,0), Point(600,600), Scalar(255,0,0), 5);
cv::imshow(“window”, annotated_frame);

The above code example does not actually draw any line to my Mat. I’ve also tested this using different line colours, as well as initializing a simple black matrix and trying to draw on that - still nothing draws. I see the same behaviour using rectangle()

i do not think, your drawing code is the problem,
you only see an updated image from imshow(), if you add a ‘cv::waitKey(some_millis)’

alternatively, try to imwrite it to disk (just to check)

I’ve done it with waitKey as well, and same behaviour.
imwrite to disk also produced no drawn lines (plain black image in example below).

int main()
{
Mat image(500,500,CV_8UC3, Scalar(0,0,0));

if(!image.data)
{
cout << “Error no data in image” << endl;
return 0;
}

Point p1(0,0), p2(400,400);
int thickness = 2;
Scalar colour(255,0,0);

line(image, p1, p2, colour, thickness, LINE_8);
imwrite(“image.jpg”, image);
waitKey(1);

return 0;
}

the code seems to be correct and I can see a blue line on a black background if I replace

 imwrite(“image.jpg”, image);
 waitKey(1);

with

imshow("x",image);
waitKey(0); //wait until key press

you can also print the matrix to console with cout << image; to check if all elements are still zero or if some are set to 255. I suggest to reduce the image size before you do that.

1 Like

is your computer screen misadjusted so that it can’t show you blue?

do you have a blue light filter app?

can you see blue things with your eyes?

some monitor test pages: