Example usage for org.opencv.imgproc Imgproc circle

List of usage examples for org.opencv.imgproc Imgproc circle

Introduction

In this page you can find the example usage for org.opencv.imgproc Imgproc circle.

Prototype

public static void circle(Mat img, Point center, int radius, Scalar color, int thickness) 

Source Link

Usage

From source file:app.GUI2.java

/**
 * this function preproces image to draw helper figures on top of image and
 * then calls updateView()/*from w  w  w .java  2  s.co  m*/
 */
private void updateDrawings(Mat unprocesedImage) {
    try {
        image = unprocesedImage.clone();
        // draw Points as circles
        if (pointA1 != null) {
            Imgproc.circle(image, pointA1, 10, new Scalar(0, 0, 128), 2);
        }
        if (pointA2 != null) {
            Imgproc.circle(image, pointA2, 10, new Scalar(0, 0, 255), 2);
        }
        if (pointB1 != null) {
            Imgproc.circle(image, pointB1, 10, new Scalar(128, 0, 0), 2);
        }
        if (pointB2 != null) {
            Imgproc.circle(image, pointB2, 10, new Scalar(255, 0, 0), 2);
        }
        // draw rectangles of selected circles
        if (pointA1 != null & pointA2 != null) {
            Imgproc.rectangle(image, pointA1, pointA2, new Scalar(0, 0, 255), 2);
        }
        if (pointB1 != null & pointB2 != null) {
            Imgproc.rectangle(image, pointB1, pointB2, new Scalar(255, 0, 0), 2);
        }

        updateView(image);
    } catch (Exception e) {
        System.err.println("Tryied to Draw without loading image" + e);
    }

}

From source file:com.astrocytes.core.operationsengine.OperationsImpl.java

License:Open Source License

@Deprecated
private Mat drawNeuronsCenters(Mat src) {
    if (src == null) {
        src = sourceImage.clone();//  w  w  w.  j ava  2s.  co m
    }
    if (neurons == null) {
        return src;
    }

    Mat result = src.clone();
    Scalar color = new Scalar(250, 10, 19);

    for (Neuron neuron : neurons) {
        Imgproc.circle(result, neuron.getCenter(), 4, color, 2);
    }

    return result;
}

From source file:com.astrocytes.core.operationsengine.OperationsImpl.java

License:Open Source License

@Deprecated
private Mat drawLayerBounds() {
    if (layerBounds == null) {
        return sourceImage;
    }//from ww  w  .java2 s. c o m

    Mat result = sourceImage.clone();

    for (int i = 0; i < layerBounds.rows(); i++) {
        Scalar color = new Scalar(250, 20, 18);
        if (i == 0 || i == layerBounds.rows() - 1) {
            color = new Scalar(18, 20, 250);
        }

        for (int j = 0; j < layerBounds.cols(); j++) {
            Imgproc.circle(result, new Point(j, layerBounds.get(i, j)[0]), 1, color, -1);
        }
    }

    return result;
}

From source file:com.astrocytes.core.operationsengine.OperationsImpl.java

License:Open Source License

private void findNeurons() {
    if (this.preparedImage == null) {
        makePreparedImage();/*from w ww.j av  a 2s  . c  o  m*/
    }

    int minNeuronRadius = 12;
    int maxNeuronRadius = 27;
    int stepSize = 3;

    neurons = new ArrayList<Neuron>();

    for (int step = maxNeuronRadius; step >= minNeuronRadius; step -= stepSize) {
        Mat stepImage = CoreOperations.erode(this.preparedImage, step);

        for (Neuron neuron : neurons) {
            Scalar blackColor = new Scalar(0);
            Imgproc.circle(stepImage, neuron.getCenter(), (int) (1.8f * neuron.getRadius()), blackColor,
                    Core.FILLED);
        }

        List<Neuron> neuronsInStep = findNeuronsInStep(stepImage, step);

        for (Neuron neuron : neuronsInStep) {
            //TODO: check for astrocyte collision
            if (!neurons.contains(neuron)) {
                neurons.add(neuron);
            }
        }
    }
}

From source file:com.astrocytes.core.operationsengine.OperationsImpl.java

License:Open Source License

private Mat applyRayCastingSegmentation() {
    //Mat cannyEdges = CoreOperations.cannyFilter(sourceImage, 26, 58);
    Mat contours = new Mat(preparedImage.rows(), preparedImage.cols(), CvType.CV_32S);
    int contoursCount = /*neurons.size();*/ CoreOperations
            .drawAllContours(CoreOperations.erode(preparedImage, 5), contours);
    Mat result = new Mat(preparedImage.rows(), preparedImage.cols(), preparedImage.type());//CoreOperations.or(CoreOperations.and(cannyEdges, CoreOperations.grayscale(preparedImage)), contours);
    //cannyEdges.release();

    //Mat markers = new Mat(contours.rows(), contours.cols(), CvType.CV_32S);
    //contours.copyTo(markers);
    contours.convertTo(contours, CvType.CV_32S);

    for (Neuron neuron : neurons) {
        int x = (int) neuron.getCenter().x;
        int y = (int) neuron.getCenter().y;
        int color = (int) preparedImage.get(y, x)[0];
        /*contours.put(y, x, color);
        contours.put(y - 2, x, color);//from www .ja  v  a 2s  .  c  om
        contours.put(y + 2, x, color);
        contours.put(y, x - 2, color);
        contours.put(y, x + 2, color);*/
        Imgproc.circle(contours, neuron.getCenter(), (int) (0.4f * neuron.getRadius()), new Scalar(color), -1);
    }

    Imgproc.watershed(sourceImage, contours);

    for (int i = 0; i < contours.rows(); i++) {
        for (int j = 0; j < contours.cols(); j++) {
            int index = (int) contours.get(i, j)[0];
            if (index == -1) {
                result.put(i, j, 0, 0, 0);
            } else if (index <= 0 || index > contoursCount) {
                result.put(i, j, 0, 0, 0);
            } else {
                if (index == 255) {
                    result.put(i, j, 0, 0, 0/*sourceImage.get(i, j)*/);
                } else {
                    result.put(i, j, index, index, index);
                }
            }
        }
    }

    result = CoreOperations.erode(result, 2);
    result = CoreOperations.dilate(result, 3);

    contours.release();

    contours = sourceImage.clone();
    CoreOperations.drawAllContours(result, contours);

    return contours;
}

From source file:com.github.mbillingr.correlationcheck.ImageProcessor.java

License:Open Source License

public List<Point> extractPoints() {
    Mat gray = new Mat();//work_width, work_height, CvType.CV_8UC1);
    Mat binary = new Mat();

    Mat kernel = Mat.ones(3, 3, CvType.CV_8UC1);

    debugreset();/*from   w  w  w  . jav a2s.  c om*/

    Mat image = load_transformed();
    working_image = image.clone();
    debugsave(image, "source");

    Imgproc.cvtColor(image, gray, Imgproc.COLOR_RGB2GRAY);
    debugsave(gray, "grayscale");

    Imgproc.GaussianBlur(gray, gray, new Size(15, 15), 0);
    debugsave(gray, "blurred");

    //Imgproc.equalizeHist(gray, gray);
    //debugsave(gray, "equalized");

    Imgproc.adaptiveThreshold(gray, binary, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY_INV,
            129, 5);
    //Imgproc.threshold(gray, binary, 0, 255, Imgproc.THRESH_BINARY_INV + Imgproc.THRESH_OTSU);
    //Imgproc.threshold(gray, binary, 128, 255, Imgproc.THRESH_BINARY_INV);
    debugsave(binary, "binary");

    Imgproc.morphologyEx(binary, binary, Imgproc.MORPH_CLOSE, kernel);
    debugsave(binary, "closed");

    Imgproc.morphologyEx(binary, binary, Imgproc.MORPH_OPEN, kernel);
    debugsave(binary, "opened");

    List<MatOfPoint> contours = new ArrayList<>();
    Mat hierarchy = new Mat();
    Imgproc.findContours(binary, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE); // is binary is now changed
    Imgproc.drawContours(image, contours, -1, new Scalar(0, 0, 255), 3);
    debugsave(image, "contours");

    List<PointAndArea> points = new ArrayList<>();

    for (MatOfPoint cnt : contours) {
        MatOfPoint2f c2f = new MatOfPoint2f();
        c2f.fromArray(cnt.toArray());
        RotatedRect rr = Imgproc.minAreaRect(c2f);

        double area = Imgproc.contourArea(cnt);

        if (rr.size.width / rr.size.height < 3 && rr.size.height / rr.size.width < 3 && rr.size.width < 64
                && rr.size.height < 64 && area > 9 && area < 10000) {
            points.add(new PointAndArea((int) area, rr.center));
        }
    }

    List<Point> final_points = new ArrayList<>();

    Collections.sort(points);
    Collections.reverse(points);
    int prev = -1;
    for (PointAndArea p : points) {
        Log.i("area", Integer.toString(p.area));
        if (prev == -1 || p.area >= prev / 2) {
            prev = p.area;
            Imgproc.circle(image, p.point, 10, new Scalar(0, 255, 0), 5);
            final_points.add(new Point(1 - p.point.y / work_height, 1 - p.point.x / work_width));
        }
    }
    debugsave(image, "circles");

    return final_points;
}

From source file:com.raulh82vlc.face_detection_sample.opencv.render.FaceDrawerOpenCV.java

License:Apache License

public static void drawFaceShapes(Rect face, Mat matrixRGBA) {
    Point start = face.tl();/*from   ww w . j  ava2 s  .c  o  m*/
    int h = (int) start.y + (face.height / 2);
    int w = (int) start.x + (face.width / 2);
    Imgproc.rectangle(matrixRGBA, start, face.br(), FACE_RECT_COLOR, 3);
    Point center = new Point(w, h);
    Imgproc.circle(matrixRGBA, center, 10, new Scalar(255, 0, 0, 255), 3);
}

From source file:com.raulh82vlc.face_detection_sample.opencv.render.FaceDrawerOpenCV.java

License:Apache License

public static void drawIrisCircle(Mat matrixRgba, Core.MinMaxLocResult minMaxLocResult) {
    Imgproc.circle(matrixRgba, minMaxLocResult.minLoc, 2, new Scalar(255, 255, 255, 255), 2);
}

From source file:contador_de_moedas.Circulo.java

private Mat doCirciloHough(Mat imgIn) {
    int valor = 0;
    baseImageList();// www.ja  v a2s. c  o  m
    Reconhecimento _reco;
    Imgproc.cvtColor(imgIn, imgIn, Imgproc.COLOR_BGR2GRAY);
    /*Imgproc.erode(imgIn, imgIn, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2, 2)));
     Imgproc.dilate(imgIn, imgIn, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2, 2)));*/

    double min_dist_Centro = imgIn.rows() / 8.0;
    /*
     Imgproc.HoughCircles(imageB, circles, method, dp, minDist, param1, param2, minRadius, maxRadius)
     imageB: Imagem de entrada (tons de cinza)
     circles: um vector que armazena conjuntos de 3 valores: Xc, Yc, r para cada crculo detectado.
     method: CV_HOUGH_GRADIENT definir o mtodo de deteco. Atualmente, esse  o nico disponvel em OpenCV
     dp: (1) A razo inversa da resoluo
     min_dist: (imgIn.rows / 8 ) A distncia mnima entre centros detectados
     param1: (200 limite superior para o detector de bordas Canny interna) limite superior para o detector de bordas Canny interna
     param2: (100* Limiar para deteco de centro)Limiar para deteco de centro.
     minRadius: (0) raio minimo a ser detectado. Se for desconhecida, colocar zero como padrao.
     maxRadius: (maxRadius) raio maximo a ser detectado. Se desconhecida, colocar zero como padrao   
     */
    Imgproc.HoughCircles(imgIn, circles, Imgproc.CV_HOUGH_GRADIENT, 1, min_dist_Centro, param1, param2,
            minRadius, maxRadius);

    rowsCols[0] = circles.rows();
    rowsCols[1] = circles.cols();

    for (int i = 0; i < circles.cols(); i++) {
        _reco = new Reconhecimento();
        double data[] = circles.get(0, i);
        Point pt = new Point(Math.round(data[0]), Math.round(data[1]));
        int raio = (int) Math.round(data[2]);

        if (data[2] > 20.0 && data[2] < 28.0) {
            valor = 10;
            setSomatorio(getSomatorio() + valor);
        } else if (data[2] > 27.0 && data[2] < 32.0) {
            valor = 5;
            setSomatorio(getSomatorio() + valor);
        } else if (data[2] > 32.0 && data[2] < 33.0) {
            valor = 50;
            setSomatorio(getSomatorio() + valor);
        } else if (data[2] > 33.5 && data[2] < 36.0) {
            valor = 25;
            setSomatorio(getSomatorio() + valor);
        } else if (data[2] > 35.0 && data[2] < 40.0) {
            valor = 100;
            setSomatorio(getSomatorio() + valor);
        }
        resultados.add(" r:" + (int) raio + "   (X:" + (int) pt.x + "-Y:" + (int) pt.y + ") Val: " + valor);
        vetMat[i] = _reco.CriaMascara(pt, data[2], imgIn);
        output = _reco.CalculaHistograma(vetMat[i], imageA);

        /*  System.out.println("histogram\n"+output.dump());
         for (int j = 0; j < vetMatFile.length - 1; j++) {
         Mat ab = vetMatFile[j];
         System.out.println("histogram\n"+vetMatFile[j].dump());
         double distance = Imgproc.compareHist(output, vetMatFile[j], Imgproc.CV_COMP_CORREL);
                
         System.out.print("ok");
         }*/

        if (criaBase) {
            FileWriter arq = null;
            try {
                String nome = "X" + (int) pt.x + "Y" + (int) pt.y + "R" + (int) raio;
                // Imgcodecs.imwrite("baseConhecimento/" + nome + "M.png", vetMat[i]);
                arq = new FileWriter("baseConhecimento/" + nome + ".txt");
                PrintWriter gravarArq = new PrintWriter(arq);
                gravarArq.print(output.dump());
                arq.close();
                // Imgcodecs.imwrite("baseConhecimento/" + nome + ".yml", output);
            } catch (IOException ex) {
                Logger.getLogger(Circulo.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    arq.close();
                } catch (IOException ex) {
                    Logger.getLogger(Circulo.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        Imgproc.circle(imageA, pt, raio, new Scalar(0, 0, 255), 2);
        Imgproc.circle(imageA, pt, 2, new Scalar(0, 255, 0), 1);
    }
    return imageA;
}

From source file:it.baywaylabs.jumpersumo.FrameDisplayCV.java

License:Open Source License

/**
 * This method find a qr-code in the view cam and execute some control.
 *
 * @throws ChecksumException//from w ww .  j  av a  2  s . c  om
 * @throws FormatException
 */
private void zxing() throws ChecksumException, FormatException {

    int[] intArray = new int[bitmapOriginal.getWidth() * bitmapOriginal.getHeight()];
    //copy pixel data from the Bitmap into the 'intArray' array
    bitmapOriginal.getPixels(intArray, 0, bitmapOriginal.getWidth(), 0, 0, bitmapOriginal.getWidth(),
            bitmapOriginal.getHeight());

    LuminanceSource source = new RGBLuminanceSource(bitmapOriginal.getWidth(), bitmapOriginal.getHeight(),
            intArray);

    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    Reader reader = new QRCodeMultiReader();

    String sResult = "";
    Double AREA_RIFERIMENTO = 11500.0;

    try {

        Result result = reader.decode(bitmap);
        sResult = result.getText();
        if (result.getBarcodeFormat().compareTo(BarcodeFormat.QR_CODE) == 0) {

            Log.d(TAG, "SI! E' Un QRCode");
            if ("jump".equalsIgnoreCase(sResult) && this.deviceController != null && this.flag_execute_qrcode) {
                deviceController.getFeatureJumpingSumo().sendAnimationsJump(
                        ARCOMMANDS_JUMPINGSUMO_ANIMATIONS_JUMP_TYPE_ENUM.ARCOMMANDS_JUMPINGSUMO_ANIMATIONS_JUMP_TYPE_HIGH);
            }
        }

        ResultPoint[] points = result.getResultPoints();
        Log.d(TAG, "PUNTI: " + points.toString());

        Point a = new Point(points[0].getX(), points[0].getY());
        Point b = new Point(points[2].getX(), points[2].getY());
        Rect rect = new Rect(a, b);

        Log.d(TAG, "Area del rettangolo: " + rect.area());
        if (rect.area() < AREA_RIFERIMENTO)
            Log.w(TAG, "Mi devo avvicinare!");
        else
            Log.w(TAG, "Mi devo allontanare!");

        Imgproc.rectangle(this.imgMAT, new Point(points[0].getX(), points[0].getY()),
                new Point(points[2].getX(), points[2].getY()), new Scalar(0, 255, 0), 3);
        Log.d(TAG, sResult);
        Point center = new Point(0, 0);

        Imgproc.circle(this.imgMAT, center, 10, new Scalar(0, 0, 255), 2);
    } catch (Resources.NotFoundException e) {
        Log.e(TAG, "Code Not Found");
        e.printStackTrace();
    } catch (NotFoundException e) {
        e.printStackTrace();
    }

}