0% found this document useful (0 votes)
76 views2 pages

Using Namespace Using Namespace New: #Include #Include

This document contains code for two OpenCV programs: 1. A program that reads an image file, displays the image, and waits for a key press. 2. A program that uses a Haar cascade classifier to detect faces in real-time video from a webcam. It draws rectangles around any detected faces and displays the number of faces detected.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views2 pages

Using Namespace Using Namespace New: #Include #Include

This document contains code for two OpenCV programs: 1. A program that reads an image file, displays the image, and waits for a key press. 2. A program that uses a Haar cascade classifier to detect faces in real-time video from a webcam. It draws rectangles around any detected faces and displays the number of faces detected.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Đọc ảnh:

#include
<opencv2\highgui\highgui.hpp>#include<iostream>using
namespace cv;using namespace std;int main() {
char *DD = new char[100]; //Luu duong dan
cout << "Nhap duong dan: "; cin >> DD;
Mat image; //Tao ma tran anh image
image = imread(DD);//Doc anh dau vao
if (!image.data) { //Kiem tra anh co doc duoc khong
cout << "Khong the tim thay anh";
system("pause");
exit(0);
}
namedWindow("PICTURE", WINDOW_NORMAL);
imshow("PICTURE", image);
waitKey(0); }
Nhận diện gương mặt:
#include <iostream>#include
<opencv2\core\core.hpp>#include
<opencv2\highgui\highgui.hpp>#include
<opencv2\imgproc\imgproc.hpp>#include
<opencv2\objdetect\objdetect.hpp>
using namespace cv;using namespace std;int main() {Mat
image;
vector<Rect> faces;
CascadeClassifier nhandien;
VideoCapture camera;
camera.open(0);

nhandien.load("C:\\openCV\\build\\etc\\haarcascades\\haar
cascade_frontalface_alt.xml");
while (1) {
camera.read(image);
nhandien.detectMultiScale(image, faces, 1.1,
2, CV_HAAR_SCALE_IMAGE, Size(30, 30));
if (faces.empty()){
cout << "Khong phat hien mat nguoi!"
<< endl;
}
for (int i = 0; i < faces.size(); ++i)
rectangle(image, faces.at(i),
CV_RGB(200, 0, 0), 2);
cout << "So mat phat hien duoc: " <<
faces.size() << endl;
imshow("PHAT HIEN GUONG MAT", image);
cvWaitKey(10);
}
waitKey(0);}

You might also like