# C++ line() function not drawing anything

**URL:** https://forum.opencv.org/t/c-line-function-not-drawing-anything/20668
**Category:** C++
**Tags:** programming
**Created:** [March 28, 2025, 3:22pm UTC](https://forum.opencv.org/t/c-line-function-not-drawing-anything/20668 "2025-03-28T15:22:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![lawcata](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/lawcata/32/12266_2.png) [@lawcata](https://forum.opencv.org/u/lawcata)
#### Post date: [March 28, 2025, 3:22pm UTC](https://forum.opencv.org/t/c-line-function-not-drawing-anything/20668/1 "2025-03-28T15:22:00Z")

</div>

> 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()

---

<div class="post-metadata">

### Author: ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)
#### Post date: [March 28, 2025, 3:45pm UTC](https://forum.opencv.org/t/c-line-function-not-drawing-anything/20668/2 "2025-03-28T15:45:04Z")

</div>

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)

---

<div class="post-metadata">

### Author: ![lawcata](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/lawcata/32/12266_2.png) [@lawcata](https://forum.opencv.org/u/lawcata)
#### Post date: [March 28, 2025, 6:43pm UTC](https://forum.opencv.org/t/c-line-function-not-drawing-anything/20668/3 "2025-03-28T18:43:28Z")

</div>

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;  
> }

---

<div class="post-metadata">

### Author: ![BadTrip](https://avatars.discourse-cdn.com/v4/letter/b/e99b99/32.png) [@BadTrip](https://forum.opencv.org/u/BadTrip)
#### Post date: [March 28, 2025, 7:24pm UTC](https://forum.opencv.org/t/c-line-function-not-drawing-anything/20668/4 "2025-03-28T19:24:42Z")

</div>

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

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

```

with

```auto
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.

---

<div class="post-metadata">

### Author: ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)
#### Post date: [March 29, 2025, 11:32am UTC](https://forum.opencv.org/t/c-line-function-not-drawing-anything/20668/5 "2025-03-29T11:32:26Z")

</div>

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:

- [Online monitor test - monitest](https://monitest.ru/en/)
- [Colour test screen](https://www.ledr.com/colours/multi.htm)
- [EIZO monitors for offices, photos & design, medicine, gaming and industry](https://www.eizo.be/monitor-test/)
- [LCD monitor test images](http://www.lagom.nl/lcd-test/) (might need a minute to become available after first request)
