How can i detected and controll object opencv?

66 Views Asked by At

I am using an android camera that should control a robot. By selecting an object on a screen, the robot should follow this object. I detected contours on the images and also a bounding rectangle, however I don't know how to proceed any further.

    Mat src = new Mat();
    Utils.bitmapToMat(bmp, src);
    Mat gray = new Mat();
    Imgproc.cvtColor(src, gray, Imgproc.COLOR_RGBA2GRAY);

    Imgproc.Canny(gray, gray, 100, 200);
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Mat hierarchy = new Mat();
    // find contours:
    Imgproc.findContours(gray, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
    for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++) {
        Imgproc.drawContours(src, contours, contourIdx, new Scalar(1, 1, 255), 1);
        org.opencv.core.Rect rect = Imgproc.boundingRect(contours.get(contourIdx));
        Imgproc.rectangle(src, rect.tl(), rect.br(), Scalar.all(Color.BLUE), 2);
        
    }
    Core.extractChannel(gray, src, 0);
    Bitmap tempBmp1 = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
    Utils.matToBitmap(src, tempBmp1);
    im_screen.setImageBitmap(tempBmp1);

How can I do this in Java to get an image like this? display each object separately?

img

0

There are 0 best solutions below