Java Code Examples for org.opencv.core.Core#rectangle()

The following examples show how to use org.opencv.core.Core#rectangle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraCalibrationScreen.java    From opencv-fun with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void update () {
	// draw cam view
	Mat image = app.getCamera().nextFrame();
	
	app.getCameraView().setImage(image);
	
	Mat fb = app.getProjectorView().createBuffer();
	Core.rectangle(fb, new Point(0, 0), new Point(fb.cols(), fb.rows()), new Scalar(0, 0, 0), -1);
	Core.rectangle(fb, new Point(20, 20), new Point(fb.cols()-40, fb.rows()-20), new Scalar(255, 255, 255), 1);
	app.getProjectorView().setImage(fb);
}
 
Example 2
Source File: Cluster.java    From opencv-fun with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void main (String[] args) {		
	CVLoader.load();
	Mat img = Mat.zeros(200, 200, CvType.CV_8UC3);
	Core.rectangle(img, new Point(0, 0), new Point(100, 200), new Scalar(0, 255, 0), -1);
	Core.rectangle(img, new Point(100, 0), new Point(200, 200), new Scalar(0, 0, 255), -1);
	
	Mat clusters = cluster(img, 2).get(0);
	
	ImgWindow.newWindow(img).setTitle("img");;		
	ImgWindow.newWindow(clusters).setTitle("clusters");
}
 
Example 3
Source File: FdActivity.java    From open-quartz with Apache License 2.0 5 votes vote down vote up
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());
    }

    // Draw rectangles
    Rect[] facesArray = faces.toArray();
    for (int i = 0; i < facesArray.length; i++) {
        Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);
    }

    return mRgba;
}
 
Example 4
Source File: Training.java    From marvel with MIT License 4 votes vote down vote up
@Override
public Mat onCameraFrame(CameraBridgeViewBase.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();

    if ((facesArray.length==1)&&(faceState==TRAINING)&&(countImages<MAXIMG)&&(!text.equals("")))
    {


        Mat m;
        Rect r=facesArray[0];


        m=mRgba.submat(r);
        mBitmap = Bitmap.createBitmap(m.width(),m.height(), Bitmap.Config.ARGB_8888);


        Utils.matToBitmap(m, mBitmap);

        Message msg = new Message();
        String textTochange = "IMG";
        msg.obj = textTochange;
        mHandler.sendMessage(msg);
        if (countImages<MAXIMG)
        {
            fr.add(m, text);
            countImages++;
        }

    }
    for (int i = 0; i < facesArray.length; i++)
        Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);

    return mRgba;
}
 
Example 5
Source File: TLDView.java    From OpenTLDAndroid with Apache License 2.0 4 votes vote down vote up
private static void drawBox(Mat image, final Rect box, final Scalar colour){
	if(box != null){
		Core.rectangle(image, box.tl(), box.br(), colour);
	}
}