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

The following examples show how to use org.opencv.core.Core#rectangle() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@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
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 Project: open-quartz   File: FdActivity.java    License: 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 Project: marvel   File: Training.java    License: 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 Project: OpenTLDAndroid   File: TLDView.java    License: 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);
	}
}