Java Code Examples for org.opencv.core.Mat

The following examples show how to use org.opencv.core.Mat. 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
Source Project: sudokufx   Source File: Converters.java    License: Apache License 2.0 6 votes vote down vote up
public static void Mat_to_vector_vector_KeyPoint(Mat m, List<MatOfKeyPoint> kps) {
    if (kps == null)
        throw new IllegalArgumentException("Output List can't be null");

    if (m == null)
        throw new IllegalArgumentException("Input Mat can't be null");

    List<Mat> mats = new ArrayList<Mat>(m.rows());
    Mat_to_vector_Mat(m, mats);
    for (Mat mi : mats) {
        MatOfKeyPoint vkp = new MatOfKeyPoint(mi);
        kps.add(vkp);
        mi.release();
    }
    mats.clear();
}
 
Example 2
Source Project: MOAAP   Source File: Converters.java    License: MIT License 6 votes vote down vote up
public static void Mat_to_vector_KeyPoint(Mat m, List<KeyPoint> kps) {
    if (kps == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_64FC(7) != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_64FC(7) != m.type() ||  m.cols()!=1\n" + m);

    kps.clear();
    double[] buff = new double[7 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        kps.add(new KeyPoint((float) buff[7 * i], (float) buff[7 * i + 1], (float) buff[7 * i + 2], (float) buff[7 * i + 3],
                (float) buff[7 * i + 4], (int) buff[7 * i + 5], (int) buff[7 * i + 6]));
    }
}
 
Example 3
Source Project: MOAAP   Source File: Converters.java    License: MIT License 6 votes vote down vote up
public static void Mat_to_vector_Mat(Mat m, List<Mat> mats) {
    if (mats == null)
        throw new java.lang.IllegalArgumentException("mats == null");
    int count = m.rows();
    if (CvType.CV_32SC2 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32SC2 != m.type() ||  m.cols()!=1\n" + m);

    mats.clear();
    int[] buff = new int[count * 2];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        long addr = (((long) buff[i * 2]) << 32) | (((long) buff[i * 2 + 1]) & 0xffffffffL);
        mats.add(new Mat(addr));
    }
}
 
Example 4
Source Project: faceswap   Source File: Converters.java    License: Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_float(Mat m, List<Float> fs) {
    if (fs == null)
        throw new java.lang.IllegalArgumentException("fs == null");
    int count = m.rows();
    if (CvType.CV_32FC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32FC1 != m.type() ||  m.cols()!=1\n" + m);

    fs.clear();
    float[] buff = new float[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        fs.add(buff[i]);
    }
}
 
Example 5
Source Project: pasm-yolov3-Android   Source File: Net.java    License: GNU General Public License v3.0 5 votes vote down vote up
public  void forward(List<Mat> outputBlobs, List<String> outBlobNames)
{
    Mat outputBlobs_mat = new Mat();
    forward_4(nativeObj, outputBlobs_mat.nativeObj, outBlobNames);
    Converters.Mat_to_vector_Mat(outputBlobs_mat, outputBlobs);
    outputBlobs_mat.release();
    return;
}
 
Example 6
Source Project: FTCVision   Source File: Core.java    License: MIT License 5 votes vote down vote up
public static MinMaxLocResult minMaxLoc(Mat src, Mat mask) {
    MinMaxLocResult res = new MinMaxLocResult();
    long maskNativeObj=0;
    if (mask != null) {
        maskNativeObj=mask.nativeObj;
    }
    double resarr[] = n_minMaxLocManual(src.nativeObj, maskNativeObj);
    res.minVal=resarr[0];
    res.maxVal=resarr[1];
    res.minLoc.x=resarr[2];
    res.minLoc.y=resarr[3];
    res.maxLoc.x=resarr[4];
    res.maxLoc.y=resarr[5];
    return res;
}
 
Example 7
Source Project: MOAAP   Source File: Imgproc.java    License: MIT License 5 votes vote down vote up
public static RotatedRect minAreaRect(MatOfPoint2f points)
{
    Mat points_mat = points;
    RotatedRect retVal = new RotatedRect(minAreaRect_0(points_mat.nativeObj));
    
    return retVal;
}
 
Example 8
Source Project: FaceDetectDemo   Source File: Feature2D.java    License: Apache License 2.0 5 votes vote down vote up
public  void detectAndCompute(Mat image, Mat mask, MatOfKeyPoint keypoints, Mat descriptors)
{
    Mat keypoints_mat = keypoints;
    detectAndCompute_1(nativeObj, image.nativeObj, mask.nativeObj, keypoints_mat.nativeObj, descriptors.nativeObj);
    
    return;
}
 
Example 9
Source Project: SmartPaperScan   Source File: Converters.java    License: Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_float(Mat m, List<Float> fs) {
    if (fs == null)
        throw new java.lang.IllegalArgumentException("fs == null");
    int count = m.rows();
    if (CvType.CV_32FC1 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_32FC1 != m.type() ||  m.cols()!=1\n" + m);

    fs.clear();
    float[] buff = new float[count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        fs.add(buff[i]);
    }
}
 
Example 10
Source Project: FTCVision   Source File: Subdiv2D.java    License: MIT License 5 votes vote down vote up
public  void getEdgeList(MatOfFloat4 edgeList)
{
    Mat edgeList_mat = edgeList;
    getEdgeList_0(nativeObj, edgeList_mat.nativeObj);
    
    return;
}
 
Example 11
Source Project: classchecks   Source File: Test.java    License: Apache License 2.0 5 votes vote down vote up
public static void recognition() {
	String modelFilePath = "E:\\classchecks\\2017417\\train\\trainModel-20170418.xml";
	BasicFaceRecognizer model = TrainFaces.load(modelFilePath);
	Mat waitRecoMat = Imgcodecs.imread("E:\\classchecks\\2017417\\split\\14.jpg");
	
	Mat preProc = PreProcessFace.rawProcessedFace(waitRecoMat);
	//Imgproc.resize(preProc, preProc, new Size(92, 112));
	Mat reconstructMat = Recognition.reconstructFace(model, preProc);
	
	double similarity = Recognition.getSimilarity(preProc, reconstructMat);
       System.out.println("similarity=" + similarity);
       int pridictLabel = model.predict_label(preProc);
       System.out.println("pridictLabel=" + pridictLabel);
}
 
Example 12
Source Project: OpenCvFaceDetect   Source File: Features2d.java    License: Apache License 2.0 5 votes vote down vote up
public static void drawMatchesKnn(Mat img1, MatOfKeyPoint keypoints1, Mat img2, MatOfKeyPoint keypoints2, List<MatOfDMatch> matches1to2, Mat outImg, Scalar matchColor)
{
    Mat keypoints1_mat = keypoints1;
    Mat keypoints2_mat = keypoints2;
    List<Mat> matches1to2_tmplm = new ArrayList<Mat>((matches1to2 != null) ? matches1to2.size() : 0);
    Mat matches1to2_mat = Converters.vector_vector_DMatch_to_Mat(matches1to2, matches1to2_tmplm);
    drawMatchesKnn_3(img1.nativeObj, keypoints1_mat.nativeObj, img2.nativeObj, keypoints2_mat.nativeObj, matches1to2_mat.nativeObj, outImg.nativeObj, matchColor.val[0], matchColor.val[1], matchColor.val[2], matchColor.val[3]);
    
    return;
}
 
Example 13
Source Project: OpenCV-AndroidSamples   Source File: Core.java    License: MIT License 5 votes vote down vote up
public static MinMaxLocResult minMaxLoc(Mat src, Mat mask) {
    MinMaxLocResult res = new MinMaxLocResult();
    long maskNativeObj=0;
    if (mask != null) {
        maskNativeObj=mask.nativeObj;
    }
    double resarr[] = n_minMaxLocManual(src.nativeObj, maskNativeObj);
    res.minVal=resarr[0];
    res.maxVal=resarr[1];
    res.minLoc.x=resarr[2];
    res.minLoc.y=resarr[3];
    res.maxLoc.x=resarr[4];
    res.maxLoc.y=resarr[5];
    return res;
}
 
Example 14
Source Project: super-cloudops   Source File: PreImageUtilsTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPre() {
	for (int i = 1; i <= 6; i++) {
		String imgPath = "C:/Users/X240/Desktop/opencv/web/p" + i + ".jpg";
		String destPath = "C:/Users/X240/Desktop/opencv/web/";
		Mat src = GeneralUtils.matFactory(imgPath);
		src = PreImageUtils.preHandleUtils(src);
		GeneralUtils.saveImg(src, destPath + "b-" + i + ".jpg");
	}

}
 
Example 15
Source Project: FaceDetectDemo   Source File: HOGDescriptor.java    License: Apache License 2.0 5 votes vote down vote up
public  void detectMultiScale(Mat img, MatOfRect foundLocations, MatOfDouble foundWeights)
{
    Mat foundLocations_mat = foundLocations;
    Mat foundWeights_mat = foundWeights;
    detectMultiScale_1(nativeObj, img.nativeObj, foundLocations_mat.nativeObj, foundWeights_mat.nativeObj);
    
    return;
}
 
Example 16
Source Project: MOAAP   Source File: AlignMTB.java    License: MIT License 5 votes vote down vote up
public  void process(List<Mat> src, List<Mat> dst, Mat times, Mat response)
{
    Mat src_mat = Converters.vector_Mat_to_Mat(src);
    Mat dst_mat = Converters.vector_Mat_to_Mat(dst);
    process_0(nativeObj, src_mat.nativeObj, dst_mat.nativeObj, times.nativeObj, response.nativeObj);
    
    return;
}
 
Example 17
Source Project: PixaToon   Source File: Photo.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void fastNlMeansDenoising(Mat src, Mat dst, MatOfFloat h, int templateWindowSize, int searchWindowSize, int normType)
{
    Mat h_mat = h;
    fastNlMeansDenoising_0(src.nativeObj, dst.nativeObj, h_mat.nativeObj, templateWindowSize, searchWindowSize, normType);
    
    return;
}
 
Example 18
Source Project: LicensePlateDiscern   Source File: Converters.java    License: MIT License 4 votes vote down vote up
public static Mat vector_Point3i_to_Mat(List<Point3> pts) {
    return vector_Point3_to_Mat(pts, CvType.CV_32S);
}
 
Example 19
Source Project: ShootOFF   Source File: Frame.java    License: GNU General Public License v3.0 4 votes vote down vote up
public Frame(Mat mat, long timestamp) {
	this.mat = mat;
	this.timestamp = timestamp;
}
 
Example 20
/**
* <p>Predicts the response for sample(s).</p>
*
* <p>The method estimates the most probable classes for input vectors. Input
* vectors (one or more) are stored as rows of the matrix <code>samples</code>.
* In case of multiple input vectors, there should be one output vector
* <code>results</code>. The predicted class for a single input vector is
* returned by the method.</p>
*
* <p>The function is parallelized with the TBB library.</p>
*
* @param samples a samples
*
* @see <a href="http://docs.opencv.org/modules/ml/doc/normal_bayes_classifier.html#cvnormalbayesclassifier-predict">org.opencv.ml.CvNormalBayesClassifier.predict</a>
*/
   public  float predict(Mat samples)
   {

       float retVal = predict_1(nativeObj, samples.nativeObj);

       return retVal;
   }
 
Example 21
Source Project: MOAAP   Source File: Core.java    License: MIT License 3 votes vote down vote up
public static boolean solve(Mat src1, Mat src2, Mat dst, int flags)
{
    
    boolean retVal = solve_0(src1.nativeObj, src2.nativeObj, dst.nativeObj, flags);
    
    return retVal;
}
 
Example 22
Source Project: Document-Scanner   Source File: Calib3d.java    License: GNU General Public License v3.0 3 votes vote down vote up
public static void undistortPoints(Mat distorted, Mat undistorted, Mat K, Mat D)
{
    
    undistortPoints_1(distorted.nativeObj, undistorted.nativeObj, K.nativeObj, D.nativeObj);
    
    return;
}
 
Example 23
/**
* <p>Predicts the response for sample(s).</p>
*
* <p>The method estimates the most probable classes for input vectors. Input
* vectors (one or more) are stored as rows of the matrix <code>samples</code>.
* In case of multiple input vectors, there should be one output vector
* <code>results</code>. The predicted class for a single input vector is
* returned by the method.</p>
*
* <p>The function is parallelized with the TBB library.</p>
*
* @param samples a samples
*
* @see <a href="http://docs.opencv.org/modules/ml/doc/normal_bayes_classifier.html#cvnormalbayesclassifier-predict">org.opencv.ml.CvNormalBayesClassifier.predict</a>
*/
   public  float predict(Mat samples)
   {

       float retVal = predict_1(nativeObj, samples.nativeObj);

       return retVal;
   }
 
Example 24
Source Project: MOAAP   Source File: Calib3d.java    License: MIT License 3 votes vote down vote up
public static boolean stereoRectifyUncalibrated(Mat points1, Mat points2, Mat F, Size imgSize, Mat H1, Mat H2)
{
    
    boolean retVal = stereoRectifyUncalibrated_1(points1.nativeObj, points2.nativeObj, F.nativeObj, imgSize.width, imgSize.height, H1.nativeObj, H2.nativeObj);
    
    return retVal;
}
 
Example 25
Source Project: OpenCV-AndroidSamples   Source File: Calib3d.java    License: MIT License 3 votes vote down vote up
public static void composeRT(Mat rvec1, Mat tvec1, Mat rvec2, Mat tvec2, Mat rvec3, Mat tvec3)
{
    
    composeRT_1(rvec1.nativeObj, tvec1.nativeObj, rvec2.nativeObj, tvec2.nativeObj, rvec3.nativeObj, tvec3.nativeObj);
    
    return;
}
 
Example 26
Source Project: FTCVision   Source File: Core.java    License: MIT License 3 votes vote down vote up
public static void convertScaleAbs(Mat src, Mat dst, double alpha, double beta)
{
    
    convertScaleAbs_0(src.nativeObj, dst.nativeObj, alpha, beta);
    
    return;
}
 
Example 27
Source Project: MOAAP   Source File: Core.java    License: MIT License 3 votes vote down vote up
public static void copyMakeBorder(Mat src, Mat dst, int top, int bottom, int left, int right, int borderType)
{
    
    copyMakeBorder_1(src.nativeObj, dst.nativeObj, top, bottom, left, right, borderType);
    
    return;
}
 
Example 28
Source Project: LicensePlateDiscern   Source File: Calib3d.java    License: MIT License 3 votes vote down vote up
public static Mat findEssentialMat(Mat points1, Mat points2, Mat cameraMatrix)
{
    
    Mat retVal = new Mat(findEssentialMat_4(points1.nativeObj, points2.nativeObj, cameraMatrix.nativeObj));
    
    return retVal;
}
 
Example 29
Source Project: OpenCV-android   Source File: Imgproc.java    License: Apache License 2.0 3 votes vote down vote up
public static void medianBlur(Mat src, Mat dst, int ksize)
{
    
    medianBlur_0(src.nativeObj, dst.nativeObj, ksize);
    
    return;
}
 
Example 30
Source Project: SmartPaperScan   Source File: Imgproc.java    License: Apache License 2.0 3 votes vote down vote up
public static void accumulateWeighted(Mat src, Mat dst, double alpha, Mat mask)
{
    
    accumulateWeighted_0(src.nativeObj, dst.nativeObj, alpha, mask.nativeObj);
    
    return;
}