In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article to share with you is about how to use OpenCV to achieve pixel operations in C++, Xiaobian feels quite practical, so share it with you to learn, I hope you can gain something after reading this article, not much to say, follow Xiaobian to see it.
Create a new entry in the source file called main
Then introduce iostream and opencv header files above yourself and write the main method
Load Display Images
To do pixel manipulation, we first have to load an image and display it, so let's write the code to load it.
After we finish writing, let's see how it works.
Description Our images were loaded successfully
gray map
We first load the original image into a single channel grayscale image and display it, the code to write cv::waitkey(0) above.
The effect of the display
grayscale inversion
First we get the height and width of the Mat image, and then we loop through the height and width to get the value of each pixel, and we assign it again by subtracting its original value from 255.
How to get pixel values:
Single pass first gray scale
Mat.at(row,col)
If it is RGB, use
Mat.at(row,col)[0]
Mat.at(row,col)[1]
Mat.at(row,col)[2]
The code is as follows:
And when that's done, we'll print it again and see how it works.
The leftmost is the original image, the middle is the modified gray image, and the last is the image retrieved after calculation.
negation of three channels
In the example above, because we used gray_src, which is only a single channel of data, we reversed the original image to Mat.at(row,col)[0], we modified the code, using a new MAT to test, and added the number of channels to determine the image.
After writing, look at the image effect of this output
It can be seen that the effect of single-channel inversion and three-channel inversion is a bit different.
Cancel the effect of a color
Let's modify the above code by taking the src values and then b , g ,r(b with blue,g for green,r for red) and then removing a certain color, that is, assigning it 0.
Set b(blue) to 0
The effect is as follows:
Set g(green) to 0
The above is how to use OpenCV to achieve pixel operations in C++. Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.