In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use C++ OpenCV to achieve pixel painting". In daily operation, I believe many people have doubts about how to use C++ OpenCV to achieve pixel painting. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to use C++ OpenCV to achieve pixel painting". Next, please follow the editor to study!
Preparatory work
The installation process that requires the installation of OpenCV,OpenCV will not be repeated here. Besides, we have prepared a picture.
Code implementation
First, we need to add the dependency of OpenCV in the CmakeLists.txt file.
Find_package (OpenCV 4 REQUIRED) include_directories (${OPENCV_INCLUDE_DIRS}) target_link_libraries (${PROJECT_NAME} ${OpenCV_LIBRARIES})
Read a file
Std::string path = "/ path/to/img/"; cv::Mat img = cv::imread (path + "meinv.jpeg")
Get the pixel width and height of the original image, and then scale the pixel ratio.
Int height = img.size (). Height;int width = img.size (). Width;int pixel_size = 10 domestic int new_width = width / pixel_size;int new_height = height / pixel_size
According to the set pixel ratio, the original image is reduced, and then magnified two times of resize operation. In this way, the pixel image processing is completed.
Cv::Mat imgTmp;cv::resize (img, imgTmp, cv::Size (new_width, new_height), 0,0, cv::INTER_LINEAR); cv::resize (imgTmp, imgTmp, cv::Size (width/2, height/2), 0,0, cv::INTER_LINEAR)
Let's take a look at the image effect after processing.
The effect looks OK, the picture color is single, the picture size is slightly smaller, the effect will be much better.
Complete code # include # include int main () {std::string path = "/ Users/wbf/Desktop/"; cv::Mat img = cv::imread (path + "meinv.jpeg"); cv::imshow ("meinv", img); int height = img.size (). Height; int width = img.size (). Width; int pixel_size = 10; int new_width = width / pixel_size; int new_height = height / pixel_size Std::cout
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.