Ask Your Question

pablas's profile - activity

2015-08-19 06:07:54 -0600 received badge  Famous Question (source)
2015-02-17 08:36:48 -0600 received badge  Notable Question (source)
2014-11-06 10:50:58 -0600 received badge  Popular Question (source)
2014-09-15 11:50:29 -0600 received badge  Student (source)
2013-12-21 06:21:06 -0600 asked a question Drawing bounding box in java

Hello, my problem is that i want to draw bounding boxes but i can't translate tutorials from c++/python to java. Now my program can drawing all contours but i want to identify them and draw 4 rectangles from them.

There is code:

public static void getContoursFrame(){

    //Getting edited frame
    contoursFrame = editedFrame.clone();
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Mat hierarchy = new Mat();
    Imgproc.findContours(contoursFrame, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
    contoursCounter = contours.size();
    Imgproc.cvtColor(contoursFrame, contoursFrame, Imgproc.COLOR_GRAY2BGR);

    if (WebcamGame.shouldColorContours == true){
        Imgproc.drawContours(contoursFrame, contours, -1, new Scalar(255, 255, 255), 1); //Everything
        Imgproc.drawContours(contoursFrame, contours, 1, new Scalar(0, 255, 0), 2); //#1 square (green)
        Imgproc.drawContours(contoursFrame, contours, 6, new Scalar(0, 255, 255), 2); //#2 square (yellow)
        Imgproc.drawContours(contoursFrame, contours, 3, new Scalar(0, 0, 255), 2); //#3 square (red)
        Imgproc.drawContours(contoursFrame, contours, 4, new Scalar(255, 0, 0), 2); //#4 square (blue)
    } else {
        Imgproc.drawContours(contoursFrame, contours, -1, new Scalar(0, 255, 255), 1); //Everything
    }

    //Converting to BufferedImage
    MatOfByte byteContoursFrame = new MatOfByte();
    Highgui.imencode(".jpg", contoursFrame, byteContoursFrame);
    byte[] bytes = byteContoursFrame.toArray();
    InputStream in = new ByteArrayInputStream(bytes);
    try {
        imgContours = ImageIO.read(in);
    } catch (IOException e) {
        System.out.println("- Error: Can't save last ContoursFrame");

// e.printStackTrace(); } }

image description