Package org.opencv.core

Examples of org.opencv.core.Mat


        System.out.println(System.getProperty("java.library.path"));
    }

    @Test
    public void testBufferedImageToMat() throws IOException {
        Mat mat = matForImage(TEST_4_CHANNEL_IMAGE, 4);
        assertEquals(4, mat.channels());

        mat = matForImage(TEST_3_CHANNEL_IMAGE, 3);
        assertEquals(3, mat.channels());

        mat = matForImage(TEST_GRAYSCALE_IMAGE, 1);
        assertEquals(1, mat.channels());
    }
View Full Code Here


    public static Mat bufferedImageToMat(BufferedImage image) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        if (image != null) {
            Mat mat;
            int numComponents = image.getColorModel().getNumComponents();
            switch (numComponents) {
                case 1:
                    mat = new Mat(image.getHeight(), image.getWidth(), CV_8UC1);
                    break;
                case 2:
                    mat = new Mat(image.getHeight(), image.getWidth(), CV_8UC2);
                    break;
                case 3:
                    mat = new Mat(image.getHeight(), image.getWidth(), CV_8UC3);
                    break;
                case 4:
                    mat = new Mat(image.getHeight(), image.getWidth(), CV_8UC4);
                    break;
                default:
                    throw new RuntimeException("Image has an unsupportable number of channels: " + numComponents);
            }

            if (image.getType() == BufferedImage.TYPE_BYTE_INDEXED) {
                image = convertByteIndexedImage(image);
            }

            byte[] pixelData = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
            mat.put(0, 0, pixelData);

            Mat mat3;
            if (numComponents == 3) {
                mat3 = mat;
            } else {
                mat3 = new Mat(image.getHeight(), image.getWidth(), CV_8UC3);
                mat.convertTo(mat3, CV_8UC3);
            }

            return mat3;
        }
View Full Code Here

        LumifyProperties.DETECTED_OBJECT.addPropertyValue(artifactVertex, multiKey, detectedObject, property.getMetadata(), new LumifyVisibility().getVisibility(), getAuthorizations());
    }

    public List<ArtifactDetectedObject> detectObjects(BufferedImage bImage) {
        List<ArtifactDetectedObject> detectedObjectList = new ArrayList<ArtifactDetectedObject>();
        Mat image = OpenCVUtils.bufferedImageToMat(bImage);
        if (image != null) {
            MatOfRect faceDetections = new MatOfRect();
            double width = image.width();
            double height = image.height();
            for (CascadeClassifierHolder objectClassifier : objectClassifiers) {
                objectClassifier.cascadeClassifier.detectMultiScale(image, faceDetections);

                for (Rect rect : faceDetections.toArray()) {
                    ArtifactDetectedObject detectedObject = new ArtifactDetectedObject(
View Full Code Here

* @author Tamás Szeleczki <sztforums@gmail.com>
* @see <a href="http://szelinet.hu/thesis/">BSc Thesis in Engineering Information Technology</a>
*/
public class ImgConverter {
    public static Mat toMat( BufferedImage img ) {
        Mat m = new Mat(img.getWidth(), img.getHeight(), CvType.CV_8UC4);
        byte[] pixels = ((DataBufferByte)img.getRaster().getDataBuffer()).getData();
        m.put(0, 0, pixels);
        return m;
    }
View Full Code Here

*
* @see <a href="http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_extractors.html#descriptorextractor-compute">org.opencv.features2d.DescriptorExtractor.compute</a>
*/
    public  void compute(Mat image, MatOfKeyPoint keypoints, Mat descriptors)
    {
        Mat keypoints_mat = keypoints;
        compute_0(nativeObj, image.nativeObj, keypoints_mat.nativeObj, descriptors.nativeObj);

        return;
    }
View Full Code Here

*
* @see <a href="http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_extractors.html#descriptorextractor-compute">org.opencv.features2d.DescriptorExtractor.compute</a>
*/
    public  void compute(List<Mat> images, List<MatOfKeyPoint> keypoints, List<Mat> descriptors)
    {
        Mat images_mat = Converters.vector_Mat_to_Mat(images);
        List<Mat> keypoints_tmplm = new ArrayList<Mat>((keypoints != null) ? keypoints.size() : 0);
        Mat keypoints_mat = Converters.vector_vector_KeyPoint_to_Mat(keypoints, keypoints_tmplm);
        Mat descriptors_mat = new Mat();
        compute_1(nativeObj, images_mat.nativeObj, keypoints_mat.nativeObj, descriptors_mat.nativeObj);
        Converters.Mat_to_vector_vector_KeyPoint(keypoints_mat, keypoints);
        Converters.Mat_to_vector_Mat(descriptors_mat, descriptors);
        return;
    }
View Full Code Here

    }

    @Override
    public void process(Mat frame) {
        if( this.fg == null )
            this.fg = new Mat(frame.width(), frame.height(), frame.type());
        this.bgs.apply(frame, this.fg);
        if( this.isShowFg() && this.showWindow.getState() != JFrame.ICONIFIED )
            this.showWindow.show(this.fg);
    }
View Full Code Here

*
* @see <a href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#approxpolydp">org.opencv.imgproc.Imgproc.approxPolyDP</a>
*/
    public static void approxPolyDP(MatOfPoint2f curve, MatOfPoint2f approxCurve, double epsilon, boolean closed)
    {
        Mat curve_mat = curve;
        Mat approxCurve_mat = approxCurve;
        approxPolyDP_0(curve_mat.nativeObj, approxCurve_mat.nativeObj, epsilon, closed);

        return;
    }
View Full Code Here

*
* @see <a href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#arclength">org.opencv.imgproc.Imgproc.arcLength</a>
*/
    public static double arcLength(MatOfPoint2f curve, boolean closed)
    {
        Mat curve_mat = curve;
        double retVal = arcLength_0(curve_mat.nativeObj, closed);

        return retVal;
    }
View Full Code Here

*
* @see <a href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#boundingrect">org.opencv.imgproc.Imgproc.boundingRect</a>
*/
    public static Rect boundingRect(MatOfPoint points)
    {
        Mat points_mat = points;
        Rect retVal = new Rect(boundingRect_0(points_mat.nativeObj));

        return retVal;
    }
View Full Code Here

TOP

Related Classes of org.opencv.core.Mat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.