Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change the background with opencv

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to use opencv to change the background. The content is concise and easy to understand. It will definitely make your eyes shine. I hope you can gain something from the detailed introduction of this article.

Let's get to the point. After changing new clothes, I want to change my wife. After changing my name, I naturally want to change my avatar! So I went to find an opencv logo, and then used PPT to match a word, and there it was:

What was going on with this green portrait? The color really reminded me of something bad, so I thought I'd replace the background with Iron Man's vintage gold.

The idea is, first of all, to pull out the three circles of opencv, as follows:

Note that the white (255) of the binary image above is what we really dig out, that is, the background is dug out as a pickled film.

This step is the key, that is, image segmentation, this image is very simple, I can directly use HSV color space can be separated out, can also threshold ah, watershed and so on, various segmentation.

Mat srcImage, HSVImage; srcImage = imread("icon.jpg");imshow("original icon", srcImage);cvtColor(srcImage, HSVImage, COLOR_BGR2HSV);//BGR to HSV//Split matting based on HSV Mat binary_Mask;//BinaryImage inRange(HSVImage, Scalar(70, 100, 100), Scalar(115, 255, 255), binary_Mask);//BinaryImage imshow("binaryImage," binary_Mask);

Then customize a background, which is the old gold mentioned above:

//customize a background Mat backImage(srcImage.size(), CV_8UC3, Scalar(65, 168, 214));//master gold imshow("background image", backImage);

Then we mix the marinated film with the new background and original image, and it's OK:

//mix background, marinade, original image backImage.copyTo(srcImage, binary_Mask); imshow("Result image", srcImage); imwrite("New avatar.jpg", srcImage); The above content is how to change the background with opencv. Have you learned knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report