java中ellipse函数,Java Imgproc.ellipse方法代码示例

该代码段展示了一个使用OpenCV库进行人脸识别的方法。首先,定义了最小人脸尺寸,然后通过`faceCascade.detectMultiScale`检测帧中的人脸。接着,对于每个检测到的人脸,进一步使用`eyesCascade.detectMultiScale`检测眼睛。如果找到眼睛,会在原图上绘制椭圆标记。最后返回包含脸部检测结果的图像。
摘要由CSDN通过智能技术生成

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类

/**

* Detect and return a face

*

* @param frame The total webcam view. Must be in grayscale.

* @return A Mat that contains only the face

*/

public static Mat getFace(Mat frame, Mat drawFrame) {

MatOfRect faces = new MatOfRect();

// compute minimum face size (20% of the frame height)

if (absoluteFaceSize == 0) {

int height = frame.rows();

if (Math.round(height * 0.2f) > 0) {

absoluteFaceSize = Math.round(height * 0.2f);

}

}

// detect faces

faceCascade.detectMultiScale(frame, faces, 1.1, 3, 0 | CASCADE_SCALE_IMAGE,

new Size(absoluteFaceSize, absoluteFaceSize), new Size());

// each rectangle in faces is a face

Rect[] facesArray = faces.toArray();

for (int i = 0; i < facesArray.length; i++) {

Point center = new Point(facesArray[i].x + (facesArray[i].width / 2), facesArray[i].y + facesArray[i].height / 2);

Mat face = new Mat(frame, facesArray[i]);

MatOfRect eyes = new MatOfRect();

eyesCascade.detectMultiScale(face, eyes, 1.1, 2,

0 | CASCADE_SCALE_IMAGE, new Size(30, 30), new Size());

if (eyes.size().width > 0 && eyes.size().height > 0) {

Imgproc.ellipse(drawFrame, center, new Size(facesArray[i].width / 2, facesArray[i].height / 2),

0, 0, 360, new Scalar(0, 0, 0), 4, 8, 0);

}

}

return drawFrame;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值