当前位置:网站首页>Opencv learning log 19 skin grinding

Opencv learning log 19 skin grinding

2022-07-06 15:43:00 @Spring sauce

Preface

This article is mainly about opencv Application of skin grinding algorithm in image processing .

One 、 Skin grinding algorithm

// Fifth question   Skin grinding 
/* notes : image.copyTo(imageROI,mask);  hold image Copy this picture (copy to) To imageROI On ,  And image Corresponding mask The pixel value in is 0( black ) None of the pixels will be pasted imageROI On . */
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main()
{
    
	VideoCapture cap("C://Users//john//Desktop//VID1.mp4");



	double scale = 0.5;

	//0-188
	// Skin colour 
	double i_minH = 0;
	double i_maxH = 20;
	//0-255
	double i_minS = 43;
	double i_maxS = 255;
	//0-255
	double i_minV = 55;
	double i_maxV = 255;

	while (1)
	{
    
		Mat frame;
		Mat hsvMat;
		Mat detectMat;
		Mat finalpicture;
		Mat rframetemp;
		Mat backskin;
		cv::Size rect;
		rect.width = 3;
		rect.height = 3;
		cap >> frame;

		Size ResImgSiz = Size(frame.cols*scale, frame.rows*scale);
		Mat rFrame = Mat(ResImgSiz, frame.type());
		resize(frame, rFrame, ResImgSiz, INTER_LINEAR);
	

		cvtColor(rFrame, hsvMat, COLOR_BGR2HSV);  //HSV
		rFrame.copyTo(rframetemp);

		GaussianBlur(rFrame, rframetemp, rect, 5, 5);     // Mean filter grinding 
		rframetemp.copyTo(detectMat);
		cv::inRange(hsvMat, Scalar(i_minH, i_minS, i_minV), Scalar(i_maxH, i_maxS, i_maxV), detectMat);// Binarization to obtain mask

		rframetemp.copyTo(finalpicture,detectMat);  // Copy after grinding 

		bitwise_not(detectMat, backskin);

		rFrame.copyTo(finalpicture, backskin);  // Copy the ungrined part of the original drawing 
		cv::imshow("rFrame", rFrame);
		cv::imshow("finalpicture", finalpicture);
		waitKey(0);



	}

}

summary

1. The code can run directly , If you don't understand, please leave a message directly .

原网站

版权声明
本文为[@Spring sauce]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131317244961.html