JAVACV实现人脸识别代码
使用JAVACV实现人脸识别的代码如下:
// Load the OpenCV library
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
// Create a new CascadeClassifier object with the trained classifier
CascadeClassifier faceDetector = new CascadeClassifier("haarcascade_frontalface_alt.xml");
// Create a Mat object to store the image
Mat image = Imgcodecs.imread("image.jpg");
// Detect faces in the image using detectMultiScale() method and store it in an array of Rect objects
Rect[] facesArray = faceDetector.detectMultiScale(image);
// Iterate through each detected face and draw a rectangle around it
for (Rect rect : facesArray) { Imgproc.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect .height), new Scalar(0, 0, 255)); } // Save the image with the detected faces Imgcodecs .imwrite("imageWithFaces .jpg", image);
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。