Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use OpenCV to realize the function of changing blue background to white background in C++.

Shulou Source: shulou.com Published: 2022-06-03 11:00:18 10月02日 Update

This article mainly introduces how to use OpenCV in C++ to achieve the function of changing blue background to white background, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

The main steps are:

1. Convert RGB image to HSV space

two。 Take a small piece of the background 20 to 20 to calculate the average hue and saturation of the blue background.

3. Set the threshold and replace the blue background with the red background

4. Convert HSV image to RGB space

5. Filter to remove edge effect

The specific code is:

/ / change_color.cpp: defines the entry point for the console application. / / change the ID photo from blue background to red background / / # include "stdafx.h" # include # include using namespace cv;using namespace std;int main () {char * origin= "Original"; char * window= "Image"; char * str= "C:\\ Users\\ ltc\\ Desktop\ nihao.jpg"; namedWindow (origin,1); namedWindow (window,1); Mat image=imread (str); if (! image.data) {cout

Tags: Image blue color red background that is space color hue threshold model white article green saturation processing saturation document target jshield + Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft Shulou Technology NVidia macOS