# set pixel program

#### denison

Joined Oct 13, 2018
241
Hi All, Came across this fascinating program somewhere on the internet and used it in visual studio 2019. I also have opencv downloaded on my laptop. Not sure even if opencv is needed in this program.
C:
#include <windows.h>
int main()
{

HDC hdc = GetDC(GetConsoleWindow());
for (int x = 0; x < 768; ++x)
for (int y = 0; y < 768; ++y)
SetPixel(hdc, x, y, RGB(255, 0, 0));

}
Using this program I am filling in 3/4 of the console window with the brightest red possible (255). green is in the second place and blue in the third. In theory you could draw a picture with this program. It would be easier with a smaller screen, say 256. This is 3 times smaller in the console window.
This program is not of much use. I want to get a digital image into the console window. Then you can use GetPixel to see the color of any individual pixel or look at sections of the image and manipulate(edit) as desired using the for command. This appears to me to be much simpler than other methods I have seen. Can anybody suggest how I can get a image into the console window?
I will probably give up trying to use opencv for computer imaging if I can't get it simpler than the incomprehensible stuff they are feeding us on various tutorials. I originally had the same problems with Arduino until I went my own way in using it without their useless libraries. I now have great programs on arduino for programming microcontrollers to control hardware. Some good old maths do the trick. I do understand that many software programmers may not be very good mathematicians and this is why they come up with such terrible software.
You also need good hardware to go with your software. Hardware recommended by Arduino doesn't even work. I designed my own.

#### BobTPH

Joined Jun 5, 2013
3,761
This program is not of much use. I want to get a digital image into the console window
Windows has API functions that copy an entire image to a window with one call. Why are you trying to do things one pixel at a time?

Bob

#### BobTPH

Joined Jun 5, 2013
3,761

#### Yaakov

Joined Jan 27, 2019
3,565
I will probably give up trying to use opencv for computer imaging if I can't get it simpler than the incomprehensible stuff they are feeding us on various tutorials. I originally had the same problems with Arduino until I went my own way in using it without their useless libraries. I now have great programs on arduino for programming microcontrollers to control hardware. Some good old maths do the trick. I do understand that many software programmers may not be very good mathematicians and this is why they come up with such terrible software.
You also need good hardware to go with your software. Hardware recommended by Arduino doesn't even work. I designed my own.
I am unclear what you expected from OpenCV but it’s not for setting and getting pixels, it’s for computer vision. OpenCV is about AI and ML (Machine Learning). Image recognition and things like automated inspection.

That you don’t understand the tutorials doesn’t mean they are ”incomprehensible“ to others. The amount of expert effort involved in the development of OpenCV is staggering, and it is a very useful, very capable library.

That you also called Arduino libraries “useless“ makes me wonder what you think the libraries are for, or what they do. That you suggest “many software programs may not be very good mathematicians“ is also baffling. Do you really think that all the effort and constant revision by many, many contributors will result in less useful software than your naive individual effort?

I don’t mean to beat up on you but as part of F/OSS communities for a very long time I feel the need to defend both OpenCV and Arduino libraries as not only very useful but certainly more well informed and executed than “good old maths” somehow circumventing algorithms, APIs, and drivers. In any case, all of the libraries that need it have relevant mathematical portions to do the calculations required.

Maybe you should do a little basic learning about how the hardware stack operates and where the different parts: OS. drivers, libraries, and programs operate and why.

#### denison

Joined Oct 13, 2018
241
Windows has API functions that copy an entire image to a window with one call. Why are you trying to do things one pixel at a time?

Bob
computer vision is all about manipulating pixels when you get down to the basics of computer vision Bob. Driverless cars for instance use cameras to pick up objects like other cars. They make boundaries around the cars. This is a manipulation of pixels in the camera image. You don't really have to manipulate individual pixels. You can manipulate groups of pixels. You can find a contrast between the car and its surrounds to put a boundary around a car and then follow its progress.
Using the program I have shown I have made a colored strip 30 pixels wide and 950 pixels long which is the length of the visual studio console. I will next make a colored circle. I have seen this done in another program which is 'incomprehensible'. I know I am ruffling feathers here but that is just too bad. I prefer simplicity to complexity as anybody should.

#### denison

Joined Oct 13, 2018
241
I am unclear what you expected from OpenCV but it’s not for setting and getting pixels, it’s for computer vision. OpenCV is about AI and ML (Machine Learning). Image recognition and things like automated inspection.

That you don’t understand the tutorials doesn’t mean they are ”incomprehensible“ to others. The amount of expert effort involved in the development of OpenCV is staggering, and it is a very useful, very capable library.

That you also called Arduino libraries “useless“ makes me wonder what you think the libraries are for, or what they do. That you suggest “many software programs may not be very good mathematicians“ is also baffling. Do you really think that all the effort and constant revision by many, many contributors will result in less useful software than your naive individual effort?

I don’t mean to beat up on you but as part of F/OSS communities for a very long time I feel the need to defend both OpenCV and Arduino libraries as not only very useful but certainly more well informed and executed than “good old maths” somehow circumventing algorithms, APIs, and drivers. In any case, all of the libraries that need it have relevant mathematical portions to do the calculations required.

Maybe you should do a little basic learning about how the hardware stack operates and where the different parts: OS. drivers, libraries, and programs operate and why.

Yaakov refer to my reply to Bob. Arduino has a excellent reference for all its functions. I wish I could find something as good in C++. If you know how to use all of these functions you have no need of the libraries. They just make the final sketch "incomprehensible".
The final solution for driverless vehicles will be better hardware and simpler software. Several of my programs for microcontrollers in Arduino I have already used analog electronics to do the same thing. And simpler in terms of parts. I built the software to keep a physics graduate happy because he said I should have used digital electronics even though the analog solution was much better. It cost me funding for the project.

#### Yaakov

Joined Jan 27, 2019
3,565
computer vision is all about manipulating pixels when you get down to the basics of computer vision Bob. Driverless cars for instance use cameras to pick up objects like other cars. They make boundaries around the cars. This is a manipulation of pixels in the camera image. You don't really have to manipulate individual pixels. You can manipulate groups of pixels. You can find a contrast between the car and its surrounds to put a boundary around a car and then follow its progress.
Using the program I have shown I have made a colored strip 30 pixels wide and 950 pixels long which is the length of the visual studio console. I will next make a colored circle. I have seen this done in another program which is 'incomprehensible'. I know I am ruffling feathers here but that is just too bad. I prefer simplicity to complexity as anybody should.
Computer Vision, as implemented in OpenCV is about AI an Machine Learning. It's not about the trivial task of drawing lines and circles. It provides a way to recognize objects using cameras so programs can decide what to do when those objects are detected. The problems might include other AI or ML programs, but the purpose of OpenCV is to do the very hard work of detecting and identifying objects.

Using the SetPixel function—which is from a library—is not the first step on the road to OpenCV which doesn't care about the display at all, in fact.

I hope you figure out whatever it is you are doing. Good luck.

#### BobTPH

Joined Jun 5, 2013
3,761
computer vision is all about manipulating pixels when you get down to the basics of computer vision Bob.
What does this have to do with what I posted? Neither you nor I said anything about computer vision. You were asking about how to draw an image on a Windows console. I gave you a suggestion related to that.

So don't lecture me about something neither of us said anything about. For all you know I might be an expert on computer vision.

Bob

#### denison

Joined Oct 13, 2018
241
Computer Vision, as implemented in OpenCV is about AI an Machine Learning. It's not about the trivial task of drawing lines and circles. It provides a way to recognize objects using cameras so programs can decide what to do when those objects are detected. The problems might include other AI or ML programs, but the purpose of OpenCV is to do the very hard work of detecting and identifying objects.

Using the SetPixel function—which is from a library—is not the first step on the road to OpenCV which doesn't care about the display at all, in fact.

I hope you figure out whatever it is you are doing. Good luck.
I agree completely that drawing lines and circles is trivial. But what is not trivial is getpixel. Because if you have your image in the console window with the get pixel instruction you can easily look at any part of image and then manipulate pixels or groups of pixels with the set pixel instruction to put boundaries around your objects in the image, etc. Using the simple program I have shown.
So I need to know how to get the digital image I want to edit into the console window. Once I have that I can proceed from there. If you know how I can get my digital image into the console window of visual studio 19 please let me know. Once I have it there I know how to proceed.

#### MrSalts

Joined Apr 2, 2020
598
Computer Vision, as implemented in OpenCV is about AI an Machine Learning. It's not about the trivial task of drawing lines and circles.
That's like saying, MicrosoftWord is for writing legal documents and not intended for love letters. OpenCV can be used for most any graphics interpretation or manipulation.

#### BobTPH

Joined Jun 5, 2013
3,761
Why do you think an image must be displayed on a screen to manipulate it?

I gave you a resource in post #3 that would answer your question. I am not going to try to teach Windows graphics programming in a forum post, it is a little more complicated than that.

Bob

xox