• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Objdetect类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.opencv.objdetect.Objdetect的典型用法代码示例。如果您正苦于以下问题:Java Objdetect类的具体用法?Java Objdetect怎么用?Java Objdetect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Objdetect类属于org.opencv.objdetect包,在下文中一共展示了Objdetect类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: detectLargestObject

import org.opencv.objdetect.Objdetect; //导入依赖的package包/类
/**
 * 检测一张人脸
 * @param img
 * @param cascade
 * @param largestObject
 * @param scaledWidth
 */
public static void detectLargestObject(Mat img, CascadeClassifier cascade, 
		Rect largestObject, int scaledWidth) {
	int flags = Objdetect.CASCADE_FIND_BIGGEST_OBJECT;
	Size minFeatureSize = new Size(10, 10);
	float searchScaleFactor = 1.1f; // 表示有多少不同大小的人脸要搜索,设置的大检测更快,但正确率降低
	int minNeighbors = 4; // 使检测的正确率更高,通常设为3

	MatOfRect objects = new MatOfRect();
	detectObjectsCustom(img, cascade, objects, scaledWidth, flags, minFeatureSize, searchScaleFactor, minNeighbors);
	if (!objects.empty()) {
		Rect tmpRect = objects.toList().get(0);
		largestObject.x = tmpRect.x;
		largestObject.y = tmpRect.y;
		largestObject.width = tmpRect.width;
		largestObject.height = tmpRect.height;
	} else {// 返回一个无效的rect
		largestObject.x = -1;
		largestObject.y = -1;
		largestObject.width = -1;
		largestObject.height = -1;
	}
}
 
开发者ID:IaHehe,项目名称:classchecks,代码行数:30,代码来源:DetectObject.java


示例2: filter_detection_window

import org.opencv.objdetect.Objdetect; //导入依赖的package包/类
/**
 * This function groups the persistent classifications among N
 * frames in the detection_window.
 * @param frame is the actual frame classification result
 * @return The consistent classified rectangles.
 */
private List<Rect> filter_detection_window(MatOfRect frame){
	MatOfRect group = new MatOfRect();
	List<Rect> ls = new ArrayList<Rect>();
	
	detection_window.add(frame);
	if (detection_window.size() == N) {
		
		/** Join the detection_window in one MatOfRect **/
		Iterator<MatOfRect> it = detection_window.iterator();
		while (it.hasNext()) {
			ls.addAll(it.next().toList());
		}
		group.fromList(ls);
        Objdetect.groupRectangles(group, new MatOfInt(), N - 1, 0.7);
        detection_window.poll();
	}
	
	return group.toList();
}
 
开发者ID:alfonsoros88,项目名称:Andrive,代码行数:26,代码来源:Andrive.java


示例3: buildTemplate

import org.opencv.objdetect.Objdetect; //导入依赖的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;
}
 
开发者ID:raulh82vlc,项目名称:Image-Detection-Samples,代码行数:54,代码来源:EyesDetectionInteractorImpl.java


示例4: detectAndDisplay

import org.opencv.objdetect.Objdetect; //导入依赖的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());	
	}
	
		
	

}
 
开发者ID:MeAnupSarkar,项目名称:ExoVisix,代码行数:44,代码来源:FaceDetectionController.java


示例5: detectManyObject

import org.opencv.objdetect.Objdetect; //导入依赖的package包/类
/**
 * 检测多张人脸
 * 
 * @param img
 * @param cascade
 * @param objects
 * @param scaledWidth
 */
public static void detectManyObject(Mat img, CascadeClassifier cascade, MatOfRect objects, 
		int scaledWidth) {
	int flags = Objdetect.CASCADE_SCALE_IMAGE;
	Size minFeatureSize = new Size(10, 10);
	float searchScaleFactor = 1.1f;
	int minNeighbors = 3;
	detectObjectsCustom(img, cascade, objects, scaledWidth, flags,
			minFeatureSize, searchScaleFactor, minNeighbors);
}
 
开发者ID:IaHehe,项目名称:classchecks,代码行数:18,代码来源:DetectObject.java


示例6: detect

import org.opencv.objdetect.Objdetect; //导入依赖的package包/类
public List<Rect> detect(String cascade) {
        MatOfRect detections = new MatOfRect();
        String cascadePath = getHaarCascade(cascade);
        MatOfInt num = new MatOfInt(1);

        CascadeClassifier detector = new CascadeClassifier(cascadePath);

//        detector.detectMultiScale2(image, detections, num);
        // teoreticky nemusi byt rozpoznany ten objekt, ktory chceme
        // ak algoritmus nebude spravne fungovat na vacsej mnozine dat
        // tak je nutne doplnit dalsie parametre pre metodu detectMUltiscale
        // alebo doplnit logiku po spracovani
        // pre nos zatial najlepsie:
//                detector.detectMultiScale2(image, detections, num, 10, 1, Objdetect.CASCADE_DO_ROUGH_SEARCH,
//                new Size(image.width() / 4, image.width() / 4), new Size(image.width()/2, image.width()/2));
        detector.detectMultiScale2(image, detections, num, 10, 2, Objdetect.CASCADE_DO_CANNY_PRUNING,
                new Size(image.width() / 4, image.width() / 4), new Size(image.width() / 2, image.width() / 2));
        // Kontrolne zobrazenie najden\ch objektov
//        drawEllipsesFromRects(detections, new Scalar(0, 255, 0));
        // Zo zoznamu rozpoznanych objektov vybrat len ten prvy
        // aj toto moze sposobit chybovost, objektov moze byt viac
        List<Rect> detectionsList = detections.toList();

        System.out.println(detectionsList.size());

        return detectionsList;
    }
 
开发者ID:Fidentis,项目名称:Analyst,代码行数:28,代码来源:HaarCascade.java


示例7: detectAndDisplay

import org.opencv.objdetect.Objdetect; //导入依赖的package包/类
private void detectAndDisplay(final Mat frame, boolean grayIsAlreadySelected) {
    MatOfRect faces = new MatOfRect();
    Mat grayFrame = new Mat();

    if (grayIsAlreadySelected) {
        LOGGER.warn("TODO IT :-)");
    } else {
        // convert the frame in gray scale to ANOTHER frame
        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 (absoluteAreaSize == 0) {
        int height = grayFrame.rows();
        if (Math.round(height * 0.2f) > 0) {
            absoluteAreaSize = Math.round(height * 0.2f);
        }
    }

    // detect faces
    /*
    The detectMultiScale function detects objects of different sizes in the input image.
    The detected objects are returned as a list of rectangles. The parameters are:
        image Matrix of the type CV_8U containing an image where objects are detected.
        objects Vector of rectangles where each rectangle contains the detected object.
        scaleFactor Parameter specifying how much the image size is reduced at each image scale.
        minNeighbors Parameter specifying how many neighbors each candidate rectangle should have to retain it.
        flags Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.
        minSize Minimum possible object size. Objects smaller than that are ignored.
        maxSize Maximum possible object size. Objects larger than that are ignored.
    So the result of the detection is going to be in the objects parameter or in our case faces.
     */
    CASCADE_CLASSIFIER.detectMultiScale(grayFrame, faces, 1.1, 2,
            0 | Objdetect.CASCADE_SCALE_IMAGE, new Size(absoluteAreaSize, absoluteAreaSize), new Size());

    /*
    each rectangle in faces is a face: draw them!
    Let’s put this result in an array of rects and draw them on the frame, by doing so we can display the detected face are.
    As you can see we selected the color green with a transparent background: Scalar(0, 255, 0, 255).
    .tl() and .br() stand for top-left and bottom-right and they represents the two opposite vertexes.
    The last parameter just set the thickness of the rectangle’s border.
     */
    final Rect[] facesArray = faces.toArray();
    countFaces(facesArray.length);
    for (Rect aFacesArray : facesArray)
        Imgproc.rectangle(frame, aFacesArray.tl(), aFacesArray.br(), new Scalar(0, 255, 0, 255), 3);
}
 
开发者ID:Evegen55,项目名称:main_carauto_board,代码行数:51,代码来源:MagicTabController.java


示例8: detectAndDisplay

import org.opencv.objdetect.Objdetect; //导入依赖的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(0, 255, 0), 3);

			// Crop the detected faces
			Rect rectCrop = new Rect(facesArray[i].tl(), facesArray[i].br());
			Mat croppedImage = new Mat(frame, rectCrop);
			// Change to gray scale
			Imgproc.cvtColor(croppedImage, croppedImage, Imgproc.COLOR_BGR2GRAY);
			// Equalize histogram
			Imgproc.equalizeHist(croppedImage, croppedImage);
			// Resize the image to a default size
			Mat resizeImage = new Mat();
			Size size = new Size(250,250);
			Imgproc.resize(croppedImage, resizeImage, size);
			
			// check if 'New user' checkbox is selected
			// if yes start collecting training data (50 images is enough)
			if ((newUser.isSelected() && !newname.isEmpty())) {
				if (index<20) {
					Imgcodecs.imwrite("resources/trainingset/combined/" +
					random + "-" + newname + "_" + (index++) + ".png", resizeImage);
				}
			}
//			int prediction = faceRecognition(resizeImage);
			double[] returnedResults = faceRecognition(resizeImage);
			double prediction = returnedResults[0];
			double confidence = returnedResults[1];
			
//			System.out.println("PREDICTED LABEL IS: " + prediction);
			int label = (int) prediction;
			String name = "";
			if (names.containsKey(label)) {
				name = names.get(label);
			} else {
				name = "Unknown";
			}
			
			// Create the text we will annotate the box with:
//            String box_text = "Prediction = " + prediction + " Confidence = " + confidence;
            String box_text = "Prediction = " + name + " Confidence = " + confidence;
            // Calculate the position for annotated text (make sure we don't
            // put illegal values in there):
            double pos_x = Math.max(facesArray[i].tl().x - 10, 0);
            double pos_y = Math.max(facesArray[i].tl().y - 10, 0);
            // And now put it into the image:
            Imgproc.putText(frame, box_text, new Point(pos_x, pos_y), 
            		Core.FONT_HERSHEY_PLAIN, 1.0, new Scalar(0, 255, 0, 2.0));
		}
	}
 
开发者ID:oconnorhorrill,项目名称:Face-Recognition,代码行数:82,代码来源:FXController.java


示例9: detectFace

import org.opencv.objdetect.Objdetect; //导入依赖的package包/类
/**
 * Detects a face in the given frame.
 *
 * @param frame
 *            An OpenCV matrix to be checked.
 * @return A reference to the internal DetectedFace object.
 */
private DetectedFace detectFace(Mat frame)
	{
		// Initialize
		final MatOfRect faces = new MatOfRect();
		final MatOfRect profiles = new MatOfRect();
		boolean facingRight = true;
		final 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);

		final Mat profileFrame = new Mat();
		grayFrame.copyTo(profileFrame);

		// compute minimum face size (20% of the frame height)
		if (this.absoluteFaceSize == 0)
			{
				final 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());
		this.profileCascade.detectMultiScale(profileFrame, profiles, 1.1, 2, 0 | Objdetect.CASCADE_SCALE_IMAGE,
		        new Size(this.absoluteFaceSize, this.absoluteFaceSize), new Size());

		Rect[ ] profileArray = profiles.toArray();
		if (profileArray.length == 0)
			{
				Core.flip(grayFrame, profileFrame, 1);
				this.profileCascade.detectMultiScale(profileFrame, profiles, 1.1, 2,
				        0 | Objdetect.CASCADE_SCALE_IMAGE, new Size(this.absoluteFaceSize, this.absoluteFaceSize),
				        new Size());
				facingRight = false;
				profileArray = profiles.toArray();

				for (final Rect profile : profileArray)
					{
						profile.x = grayFrame.width() - profile.x - profile.width;
					}
			}

		// each rectangle in faces is a face
		final Rect[ ] facesArray = faces.toArray();

		if ((profileArray.length == 0) && (facesArray.length == 1))
			{
				processFrontalFaces(grayFrame, frame, facesArray);
			}
		else
			if ((profileArray.length == 1) && (facesArray.length == 0))
				{
					processProfiles(grayFrame, frame, profileArray, facingRight);
				}

		return detectedFace;
	}
 
开发者ID:RobertTatoian,项目名称:FaceMapping,代码行数:71,代码来源:FaceDetector.java


示例10: get_template

import org.opencv.objdetect.Objdetect; //导入依赖的package包/类
private Mat get_template(CascadeClassifier clasificator, Rect area,
		int size, boolean isLeft) {
	Mat template = new Mat();
	Mat mROI = mGray.submat(area);
	MatOfRect eyes = new MatOfRect();
	Point iris = new Point();
	Rect eye_template = new Rect();
	clasificator.detectMultiScale(mROI, eyes, 1.15, 2,
			Objdetect.CASCADE_FIND_BIGGEST_OBJECT
					| Objdetect.CASCADE_SCALE_IMAGE, new Size(30, 30),
			new Size());

	Rect[] eyesArray = eyes.toArray();
	for (int i = 0; i < eyesArray.length;) {
		Rect e = eyesArray[i];
		e.x = area.x + e.x;
		e.y = area.y + e.y;
		Rect eye_rect = new Rect((int) e.tl().x,
				(int) (e.tl().y + e.height * 0.4), (int) e.width,
				(int) (e.height * 0.6));
		mROI = mGray.submat(eye_rect);
		Mat vyrez = mRgba.submat(eye_rect);

		Core.MinMaxLocResult mmG = Core.minMaxLoc(mROI);
		Log.d(TAG, "White Circle =>Pupil");

		Core.circle(vyrez, mmG.minLoc, 2, new Scalar(255, 255, 255, 255), 2);

		iris.x = mmG.minLoc.x + eye_rect.x;
		iris.y = mmG.minLoc.y + eye_rect.y;
		eye_template = new Rect((int) iris.x - size / 2, (int) iris.y
				- size / 2, size, size);

		/*
		 * if(isLeft){ Core.putText(mRgba, "[" + mmG.minLoc.x + "," +
		 * mmG.minLoc.y + "]", new Point(iris.x + 20, iris.y + 20),
		 * Core.FONT_HERSHEY_SIMPLEX, 0.7, new Scalar(255, 255, 255, 255));
		 * }else{ Core.putText(mRgba, "[" + mmG.minLoc.x + "," +
		 * mmG.minLoc.y + "]", new Point(iris.x - 20, iris.y + 20),
		 * Core.FONT_HERSHEY_SIMPLEX, 0.7, new Scalar(255, 255, 255, 255));
		 * }
		 */

		if (isLeft) {
			tPointL = mmG.minLoc;
		} else {
			tPointR = mmG.minLoc;
		}

		Log.e(TAG, "mmG.minLoc = " + mmG.minLoc.x + " " + mmG.minLoc.y);

		Log.d(TAG, "Red Rectangale =><Eye>");
		Core.rectangle(mRgba, eye_template.tl(), eye_template.br(),
				new Scalar(255, 0, 0, 255), 2);
		template = (mGray.submat(eye_template)).clone();
		return template;
	}
	return template;
}
 
开发者ID:sarthakparui,项目名称:eyeintention,代码行数:60,代码来源:EyeIntention.java



注:本文中的org.opencv.objdetect.Objdetect类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DBOptions类代码示例发布时间:2022-05-22
下一篇:
Java MetadataValue类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap