人脸识别/人眼识别haar -- OpenCV (五)

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/video/background_segm.hpp>
#include "opencv2/calib3d/calib3d.hpp"
#include <opencv2/opencv.hpp>


using namespace std;
using namespace cv;
RNG rng;

int main(int argc, char** argv) {
	cv::Mat temp_thin_color = cv::imread("../example/93.jpg", CV_LOAD_IMAGE_UNCHANGED);
	cv::Mat temp_thin_image_color, gray_image_color, equalize_image_color;
	temp_thin_color.convertTo(temp_thin_image_color, CV_8UC1, 1, 0);

	cv::cvtColor(temp_thin_image_color, gray_image_color, CV_RGB2GRAY);
	cv::imshow("gray_image_color", gray_image_color);

	cv::equalizeHist(gray_image_color, equalize_image_color);	
	cv::imshow("equalize_image_color", equalize_image_color);

	std::vector<cv::Rect> objs;
	cv::CascadeClassifier objDetector("../haarcascades/haarcascade_frontalface_alt2.xml");
	objDetector.detectMultiScale(equalize_image_color, objs, 1.2, 2, CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));

	std::vector<cv::Rect>::const_iterator it = objs.begin();
	for (; it != objs.end(); ++it) {
		rectangle(gray_image_color, cv::Point(it->x, it->y),cv::Point(it->x + it->width, it->y + it->height),cv::Scalar(0, 255, 0), 2, CV_AA);

		std::cout << it->x << " " << it->y << " " << it->width << " " << it->height << std::endl;

		cv::Mat roi_image_color = temp_thin_image_color(cv::Rect(it->x, it->y, it->width, it->height));
		cv::imshow("roi_image_color", roi_image_color);
	}

	cv::waitKey(0);
	return 0;
}

终极那结果:

 

识别结果:108 177 335 335

 

©️2020 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值