当前位置: 首页>>代码示例>>Java>>正文


Java Imgproc.rectangle方法代码示例

本文整理汇总了Java中org.opencv.imgproc.Imgproc.rectangle方法的典型用法代码示例。如果您正苦于以下问题:Java Imgproc.rectangle方法的具体用法?Java Imgproc.rectangle怎么用?Java Imgproc.rectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opencv.imgproc.Imgproc的用法示例。


在下文中一共展示了Imgproc.rectangle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: RectangleSubROI

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat RectangleSubROI(Mat input, Rect rect) {
	final Mat maskCopyTo = Mat.zeros(input.size(), CvType.CV_8UC1); // ����copyTo������mask����С��ԭͼ����һ��
	// floodFill��mask��width��height�����������ͼ��������������أ��������ᱨ��
	final Mat maskFloodFill = Mat.zeros(new Size(input.cols() + 2, input.rows() + 2), CvType.CV_8UC1); // ����floodFill������mask���ߴ��ԭͼ��һЩ
	// Imgproc.circle(maskCopyTo, new Point(cc.x, cc.y), radius, Scalar.all(255), 2,
	// 8, 0); // ����Բ������
	Imgproc.rectangle(maskCopyTo, rect.tl(), rect.br(), Scalar.all(255), 2, 8, 0);
	Imgproc.floodFill(maskCopyTo, maskFloodFill,
			new Point((rect.tl().x + rect.br().x) / 2, (rect.tl().y + rect.br().y) / 2), Scalar.all(255), null,
			Scalar.all(20), Scalar.all(20), 4); // ��ˮ��䷨���Բ���ڲ�
	// MatView.imshow(maskFloodFill, "Mask of floodFill"); // ����floodFill������mask
	// MatView.imshow(maskCopyTo, "Mask of copyTo"); // ����copyTo������mask
	final Mat imgRectROI = new Mat();
	input.copyTo(imgRectROI, maskCopyTo); // ��ȡԲ�ε�ROI
	// MatView.imshow(imgCircularROI, "Circular ROI"); // ��ʾԲ�ε�ROI
	return imgRectROI;
}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:18,代码来源:ROI_Irregular.java

示例2: HOGDescriptor

import org.opencv.imgproc.Imgproc; //导入方法依赖的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);
}
 
开发者ID:johnhany,项目名称:MOAAP,代码行数:25,代码来源:MainActivity.java

示例3: run

import org.opencv.imgproc.Imgproc; //导入方法依赖的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.imgproc.Imgproc; //导入方法依赖的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;
}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:17,代码来源:CameraFacialRecognition.java

示例5: testFindExternalContours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Test
public void testFindExternalContours(){
    contourFinder = new StandardContourFinder();
    Mat image = Mat.zeros(100, 100, CvType.CV_8UC1);
    Imgproc.rectangle(image, new Point(10, 10), new Point(20, 20), Scalar.all(255));

    List<MatOfPoint> contours = contourFinder.findContours(image);

    List<Point> expected = Arrays.asList(new Point(10, 10), new Point(10, 20), new Point(20, 20), new Point(20, 10));

    assertEquals(1, contours.size());

    List<Point> contour = contours.get(0).toList();

    assertEquals(expected.size(), contour.size());

    for (Point point : expected) {
        assertTrue(contour.contains(point));
    }

}
 
开发者ID:kylecorry31,项目名称:Robot-Vision-API,代码行数:22,代码来源:StandardContourFinderTest.java

示例6: onCameraFrame

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

        //Get image size and draw a rectangle on the image for reference
        Mat temp = inputFrame.rgba();
        Imgproc.rectangle(temp, new Point(temp.cols()/2 - 200, temp.rows() / 2 - 200), new Point(temp.cols() / 2 + 200, temp.rows() / 2 + 200), new Scalar(255,255,255),1);
        Mat digit = temp.submat(temp.rows()/2 - 180, temp.rows() / 2 + 180, temp.cols() / 2 - 180, temp.cols() / 2 + 180).clone();
        Core.transpose(digit,digit);
        int predict_result = mnist.FindMatch(digit);
        Imgproc.putText(temp, Integer.toString(predict_result), new Point(50, 150), FONT_HERSHEY_SIMPLEX, 3.0, new Scalar(0, 0, 255), 5);

        return temp;
    }
 
开发者ID:johnhany,项目名称:MOAAP,代码行数:13,代码来源:MainActivity.java

示例7: onCameraFrame

import org.opencv.imgproc.Imgproc; //导入方法依赖的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;
}
 
开发者ID:uelordi01,项目名称:Android-opencv-native-samples,代码行数:38,代码来源:FdActivity.java

示例8: run

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
public void run() {
    synchronized (this) {
        while (runnable) {
            if (webSource.grab()) {
                try {
                    webSource.retrieve(fm);
                    Graphics g = cameraPane.getGraphics();
                    faceDetector.detectMultiScale(fm, faceDetections);
                    for (Rect rect : faceDetections.toArray()) {
                        Imgproc.rectangle(fm, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
                    }

                    Highgui.imencode(".bmp", fm, mem);
                    Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
                    BufferedImage buff = (BufferedImage) im;
                    if (g.drawImage(buff, 0, 0, getWidth(), getHeight(), 0, 0, buff.getWidth(), buff.getHeight(), null)) {

                        if (runnable == false) {
                            System.out.println("Paused ..... ");
                            this.wait();
                        }
                    }
                } catch (Exception ex) {
                    ex.toString();
                }
            }
        }
    }
}
 
开发者ID:javaspecial,项目名称:Face-detection-and-recognition-desktop-application,代码行数:31,代码来源:FaceDetectorSecurityCamera.java

示例9: testDetectManyObject

import org.opencv.imgproc.Imgproc; //导入方法依赖的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);
}
 
开发者ID:IaHehe,项目名称:classchecks,代码行数:38,代码来源:DetectObjectTest.java

示例10: detectAndDisplay

import org.opencv.imgproc.Imgproc; //导入方法依赖的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

示例11: VisionTest

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public VisionTest() {
		UsbCamera camera = CameraServer.getInstance().startAutomaticCapture(); // cam0 by default
		camera.setResolution(IMG_WIDTH, IMG_HEIGHT);
		camera.setBrightness(0);
//		camera.setExposureManual(100);
		camera.setExposureAuto();

		CvSource cs= CameraServer.getInstance().putVideo("name", IMG_WIDTH, IMG_HEIGHT);

		visionThread = new VisionThread(camera, new GripPipeline(), pipeline -> {
			Mat IMG_MOD = pipeline.hslThresholdOutput();
	        if (!pipeline.filterContoursOutput().isEmpty()) {
	            //Rect recCombine = Imgproc.boundingRect(pipeline.filterContoursOutput().get(0));
                Rect recCombine = computeBoundingRectangle(pipeline.filterContoursOutput());
                if (recCombine == null) {
                	targetDetected = false;
                	return;
                }
                targetDetected = true;
		        computeCoords(recCombine);
	            synchronized (imgLock) {
	                centerX = recCombine.x + (recCombine.width / 2);
	            }
	            
	            Imgproc.rectangle(IMG_MOD, new Point(recCombine.x, recCombine.y),new Point(recCombine.x + recCombine.width,recCombine.y + recCombine.height), new Scalar(255, 20, 0), 5);
	            
	        } else {
	        	targetDetected = false;
	        }
           
	        cs.putFrame(IMG_MOD);
	    });

	    visionThread.start();
	    Relay relay = new Relay(RobotMap.RELAY_CHANNEL, Direction.kForward);
	    relay.set(Relay.Value.kOn);
	    //this.processImage();
	}
 
开发者ID:cyborgs3335,项目名称:STEAMworks,代码行数:39,代码来源:VisionTest.java

示例12: onCameraFrame

import org.opencv.imgproc.Imgproc; //导入方法依赖的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;
}
 
开发者ID:typer9527,项目名称:FaceDetectDemo,代码行数:31,代码来源:DetectActivity.java

示例13: rectangle

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * 
* @Title: rectangle 
* @Description: 以检测的人脸图像区域数组在源图像上画矩形框
* @param mImgSRC
* @param rects
* @return
* Mat 
 */
public static Mat rectangle(Mat mImgSRC, Rect ...rects ) {
	Mat tmp = new Mat();
	mImgSRC.copyTo(tmp);
	for(Rect r : rects) {
		Imgproc.rectangle(tmp, new Point(r.x, r.y), new Point(r.x + r.width, r.y + r.height), new Scalar(0, 0, 255));
	}
	
	return tmp;
}
 
开发者ID:IaHehe,项目名称:classchecks,代码行数:19,代码来源:ImgprocessUtils.java

示例14: updateFrame

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void updateFrame()
{
    cap.read(frame);
    Imgproc.rectangle(frame, new Point(50, 50), new Point(100, 100), new Scalar(0,0,255), -1);
    p.repaint();
}
 
开发者ID:Plasmoxy,项目名称:AquamarineLake,代码行数:7,代码来源:MainFrame.java

示例15: drawRectangle

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static void drawRectangle(Mat img, Point topLeft, Point bottomRight, Color color, int thickness) {
    Imgproc.rectangle(img, topLeft, bottomRight, color.getScalarRGBA(), thickness);
}
 
开发者ID:ykarim,项目名称:FTC2016,代码行数:4,代码来源:Drawing.java


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