本文整理汇总了Java中org.opencv.core.MatOfRect.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java MatOfRect.toArray方法的具体用法?Java MatOfRect.toArray怎么用?Java MatOfRect.toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opencv.core.MatOfRect
的用法示例。
在下文中一共展示了MatOfRect.toArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: HOGDescriptor
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
void HOGDescriptor() {
Mat grayMat = new Mat();
Mat people = new Mat();
//Converting the image to grayscale
Imgproc.cvtColor(originalMat, grayMat, Imgproc.COLOR_BGR2GRAY);
HOGDescriptor hog = new HOGDescriptor();
hog.setSVMDetector(HOGDescriptor.getDefaultPeopleDetector());
MatOfRect faces = new MatOfRect();
MatOfDouble weights = new MatOfDouble();
hog.detectMultiScale(grayMat, faces, weights);
originalMat.copyTo(people);
//Draw faces on the image
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++)
Imgproc.rectangle(people, facesArray[i].tl(), facesArray[i].br(), new Scalar(100), 3);
//Converting Mat back to Bitmap
Utils.matToBitmap(people, currentBitmap);
imageView.setImageBitmap(currentBitmap);
}
示例2: onCameraFrame
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
mNativeDetector.setMinFaceSize(mAbsoluteFaceSize);
}
MatOfRect faces = new MatOfRect();
if (mDetectorType == JAVA_DETECTOR) {
if (mJavaDetector != null)
mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
} else if (mDetectorType == NATIVE_DETECTOR) {
if (mNativeDetector != null)
mNativeDetector.detect(mGray, faces);
} else {
Log.e(TAG, "Detection method is not selected!");
}
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++) {
Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);
}
//转置90度
Mat rotateMat = Imgproc.getRotationMatrix2D(new Point(mRgba.rows() / 2, mRgba.cols() / 2), 90, 1);
Imgproc.warpAffine(mRgba, mRgba, rotateMat, mRgba.size());
//以y轴翻转
Core.flip(mRgba, mRgba, 1);
return mRgba;
}
示例3: run
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
public void run() {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
String base = "C:/Books in Progress/Java for Data Science/Chapter 10/OpenCVExamples/src/resources";
CascadeClassifier faceDetector =
new CascadeClassifier(base + "/lbpcascade_frontalface.xml");
Mat image = Imgcodecs.imread(base + "/images.jpg");
MatOfRect faceVectors = new MatOfRect();
faceDetector.detectMultiScale(image, faceVectors);
out.println(faceVectors.toArray().length + " faces found");
for (Rect rect : faceVectors.toArray()) {
Imgproc.rectangle(image, new Point(rect.x, rect.y),
new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 255, 0));
}
Imgcodecs.imwrite("faceDetection.png", image);
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:21,代码来源:DetectFaceDemo.java
示例4: dobj
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
private static Mat dobj(CascadeClassifier objDetector, Mat src) {
final Mat dst = src.clone();
final MatOfRect objDetections = new MatOfRect();
objDetector.detectMultiScale(dst, objDetections);
if (objDetections.toArray().length <= 0) {
return src;
}
for (final Rect rect : objDetections.toArray()) {
Imgproc.rectangle(dst, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 0, 255), 2);
}
return dst;
}
示例5: staticFace
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
public static void staticFace(String input, String output) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.out.println("\nRunning FaceDetector");
final CascadeClassifier faceDetector = new CascadeClassifier(StaticFacialRecognition.class
.getResource("../../../../../opencv/sources/data/haarcascades_cuda/haarcascade_frontalface_alt.xml")
.getPath().substring(1));
final Mat image = Imgcodecs.imread(input);
// �������� StaticFacialRecognition.class.getResource(input).getPath().substring(1)
final MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
for (final Rect rect : faceDetections.toArray()) {
Imgproc.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 255, 0));
}
System.out.println(String.format("Writing %s", output));
Imgcodecs.imwrite(output, image);
// �������� StaticFacialRecognition.class.getResource("").getPath().substring(1) +
// output
}
示例6: detectMany
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
/**
*
* @Title: detectMany
* @Description: 检测多人图片,返回检测的人脸区域对象
* @param mImgSRC
* @return
* MatOfRect
*/
public static MatOfRect detectMany(Mat mImgSRC) {
if(mImgSRC.empty()) {
LOG.info("检测多人图片检测时没有找到图片");
return null;
}
// 人脸检测器文件的所在路径的文件夹名称数组
String [] pathKey = {ServletContextHolder.getOpenCVHaarcascades(), "haarcascade_frontalface_alt.xml"};
CascadeClassifier cascade = new CascadeClassifier(FileUtils.buildFilePath(pathKey));
if(cascade.empty()) {
LOG.info("人脸检测级联加载器为null");
return null;
}
// 记录搜索到的人脸区域
MatOfRect mOfRect = new MatOfRect();
// 用于计算缩放比例
int scaledWidth = mImgSRC.width();
detectManyObject(mImgSRC, cascade, mOfRect, scaledWidth);
if(mOfRect.toArray().length <= 0) {
LOG.info("没有检测到人脸...");
return null;
}
return mOfRect;
}
示例7: onCameraFrame
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
//Rotating the input frame
Mat mGray = inputFrame.gray();
mRgba = inputFrame.rgba();
if (mIsFrontCamera)
{
Core.flip(mRgba, mRgba, 1);
Core.flip(mGray, mGray, 1);
}
//Detecting face in the frame
MatOfRect faces = new MatOfRect();
if(haarCascade != null)
{
haarCascade.detectMultiScale(mGray, faces, 1.1, 2, 2, new Size(200,200), new Size());
}
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++)
Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), new Scalar(100), 3);
return mRgba;
}
示例8: onCameraFrame
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
mNativeDetector.setMinFaceSize(mAbsoluteFaceSize);
}
MatOfRect faces = new MatOfRect();
if (mDetectorType == JAVA_DETECTOR) {
if (mJavaDetector != null)
mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
}
else if (mDetectorType == NATIVE_DETECTOR) {
if (mNativeDetector != null)
mNativeDetector.detect(mGray, faces);
}
else {
Log.e(TAG, "Detection method is not selected!");
}
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++)
Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);
return mRgba;
}
示例9: buildTemplate
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
/**
* <p>Build a template from a specific eye area previously substracted
* uses detectMultiScale for this area, then uses minMaxLoc method to
* detect iris from the detected eye</p>
*
* @param area Preformatted Area
* @param size minimum iris size
* @param grayMat image in gray
* @param rgbaMat image in color
* @param detectorEye Haar Cascade classifier
* @return built template
*/
@NonNull
private static Mat buildTemplate(Rect area, final int size,
@NonNull Mat grayMat,
@NonNull Mat rgbaMat,
CascadeClassifier detectorEye) {
Mat template = new Mat();
Mat graySubMatEye = grayMat.submat(area);
MatOfRect eyes = new MatOfRect();
Rect eyeTemplate;
detectorEye.detectMultiScale(graySubMatEye, eyes, 1.15, 2,
Objdetect.CASCADE_FIND_BIGGEST_OBJECT
| Objdetect.CASCADE_SCALE_IMAGE, new Size(EYE_MIN_SIZE, EYE_MIN_SIZE),
new Size());
Rect[] eyesArray = eyes.toArray();
if (eyesArray.length > 0) {
Rect e = eyesArray[0];
e.x = area.x + e.x;
e.y = area.y + e.y;
Rect eyeRectangle = getEyeArea((int) e.tl().x,
(int) (e.tl().y + e.height * 0.4),
e.width,
(int) (e.height * 0.6));
graySubMatEye = grayMat.submat(eyeRectangle);
Mat rgbaMatEye = rgbaMat.submat(eyeRectangle);
Core.MinMaxLocResult minMaxLoc = Core.minMaxLoc(graySubMatEye);
FaceDrawerOpenCV.drawIrisCircle(rgbaMatEye, minMaxLoc);
Point iris = new Point();
iris.x = minMaxLoc.minLoc.x + eyeRectangle.x;
iris.y = minMaxLoc.minLoc.y + eyeRectangle.y;
eyeTemplate = getEyeArea((int) iris.x - size / 2,
(int) iris.y
- size / 2, size, size);
FaceDrawerOpenCV.drawEyeRectangle(eyeTemplate, rgbaMat);
template = (grayMat.submat(eyeTemplate)).clone();
}
return template;
}
示例10: onCameraFrame
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
@Override
// 这里执行人脸检测的逻辑, 根据OpenCV提供的例子实现(face-detection)
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
// 翻转矩阵以适配前后置摄像头
if (isFrontCamera) {
Core.flip(mRgba, mRgba, 1);
Core.flip(mGray, mGray, 1);
} else {
Core.flip(mRgba, mRgba, -1);
Core.flip(mGray, mGray, -1);
}
float mRelativeFaceSize = 0.2f;
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
}
MatOfRect faces = new MatOfRect();
if (classifier != null)
classifier.detectMultiScale(mGray, faces, 1.1, 2, 2,
new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
Rect[] facesArray = faces.toArray();
Scalar faceRectColor = new Scalar(0, 255, 0, 255);
for (Rect faceRect : facesArray)
Imgproc.rectangle(mRgba, faceRect.tl(), faceRect.br(), faceRectColor, 3);
return mRgba;
}
示例11: onCameraFrame
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
rotateFlipImage(ImageControllers.getInstance().getFlipType(),
ImageControllers.getInstance().getMakeTranspose(),
mRgba.getNativeObjAddr());
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
mNativeDetector.setMinFaceSize(mAbsoluteFaceSize);
}
MatOfRect faces = new MatOfRect();
if (mDetectorType == JAVA_DETECTOR) {
if (mJavaDetector != null)
mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
}
else if (mDetectorType == NATIVE_DETECTOR) {
if (mNativeDetector != null)
mNativeDetector.detect(mGray, faces);
Log.v(LOG_TAG, "native detect");
}
else {
Log.e(TAG, "Detection method is not selected!");
}
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++)
Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);
return mRgba;
}
示例12: detectAndDisplay
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
/**
* Method for face detection and tracking
*
* @param frame
* it looks for faces in this frame
*/
private void detectAndDisplay(Mat frame)
{
MatOfRect faces = new MatOfRect();
Mat grayFrame = new Mat();
// convert the frame in gray scale
Imgproc.cvtColor(frame, grayFrame, Imgproc.COLOR_BGR2GRAY);
// equalize the frame histogram to improve the result
Imgproc.equalizeHist(grayFrame, grayFrame);
// compute minimum face size (20% of the frame height, in our case)
if (this.absoluteFaceSize == 0)
{
int height = grayFrame.rows();
if (Math.round(height * 0.2f) > 0)
{
this.absoluteFaceSize = Math.round(height * 0.2f);
}
}
// detect faces
this.faceCascade.detectMultiScale(grayFrame, faces, 1.1, 2, 0 | Objdetect.CASCADE_SCALE_IMAGE,
new Size(this.absoluteFaceSize, this.absoluteFaceSize), new Size());
// each rectangle in faces is a face: draw them!
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++)
{
Imgproc.rectangle(frame, facesArray[i].tl(), facesArray[i].br(), new Scalar(7, 255, 90), 4);
System.out.println(facesArray[i].tl());
System.out.println(facesArray[i].br());
}
}
示例13: cutOutImage
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
/**
*
* @Title: cutOutImage
* @Description: 以Rect坐标裁剪图片
* @param src
* @param mOfRect
* @return
* List<Mat>
*/
public static List<Mat> cutOutImage(Mat src, MatOfRect mOfRect) {
List<Mat> outs = new ArrayList<Mat>();
if(src.empty() || mOfRect.toArray().length <= 0) {
return null;
}
int enlarge = 50; // 将图片的x,y坐标加大
for(Rect r : mOfRect.toArray()) {
int enlargeW = (r.x + enlarge) / r.x;
int enlargeH = (r.y + enlarge) / r.y;
r.x -= enlarge;
r.y -= enlarge;
r.width += (enlargeW * r.width);
r.height += (enlargeH * r.height);
// 确定人脸在图像中的整个边界,防止人脸在边框之外
if (r.x < 0) {
r.x = 0;
}
if (r.y < 0) {
r.y = 0;
}
if (r.x + r.width > src.cols()) {
r.x = src.cols() - r.width;
}
if (r.y + r.height > src.rows()) {
r.y = src.rows() - r.height;
}
Mat cutting = new Mat(src, r); // 裁剪图片
// System.out.println(cutting);
outs.add(cutting);
}
return outs;
}
示例14: testDetectManyObject
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
@Test
public void testDetectManyObject() {
String opencvDLL = "G:/java/JavaProjectRelease/classchecks/src/main/webapp/WEB-INF/dll/x64/opencv_java320.dll";
System.load(opencvDLL);
String haarcascade = "haarcascade_frontalface_alt.xml";
CascadeClassifier cascade = new CascadeClassifier(XMLFilePath + haarcascade);
Mat src = Imgcodecs.imread(imageDir + "/split/14.jpg");
MatOfRect objects = new MatOfRect();
int scaledWidth = src.width();
DetectObject.detectManyObject(src, cascade, objects, scaledWidth);
Rect [] rects = objects.toArray();
int i = 0;
for(Rect r : rects) {
/*Imgproc.rectangle(src, new Point(r.x-100 , r.y-100 ),
new Point(r.x + r.width + 80,
r.y + r.height + 80), new Scalar(0, 0, 255), 3);*/
Imgproc.rectangle(src, r.tl(),
r.br(), new Scalar(0, 0, 255), 3);
/*r.width += 120;
r.height += 120;
r.x -= 100;
r.y -= 100;
System.out.println(r);
Mat roi = new Mat(src, r);
Imgcodecs.imwrite("e:/classchecks/2017417/split/"+i+".jpg", roi);
i ++;*/
}
Imgcodecs.imwrite("e:/classchecks/2017417/dectctManyObject.jpg", src);
//Imgcodecs.imwrite("e:/classchecks/dectctManyObject.jpg", src);
}
示例15: onCameraFrame
import org.opencv.core.MatOfRect; //导入方法依赖的package包/类
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
}
MatOfRect faces = new MatOfRect();
if (mJavaDetector != null)
mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
Rect[] facesArray = faces.toArray();
if(isFaceRectangleEnabled){
for (int i = 0; i < facesArray.length; i++)
Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);
}
if (facesArray.length == 1)
{
chooseFaceRect = facesArray[0].clone();
isFaceRectChosen = true;
}
return mRgba;
}