org.opencv.core.Mat Java Examples

The following examples show how to use org.opencv.core.Mat. 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 check out the related API usage on the sidebar.
Example #1
Source File: Converters.java    From MOAAP with 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 #2
Source File: Converters.java    From MOAAP with 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 File: Converters.java    From sudokufx with 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 #4
Source File: Photo.java    From PixaToon with 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 #5
Source File: HOGDescriptor.java    From FaceDetectDemo with 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 #6
Source File: Converters.java    From SmartPaperScan with 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 #7
Source File: Converters.java    From faceswap with 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 #8
Source File: AlignMTB.java    From MOAAP with 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 #9
Source File: Net.java    From pasm-yolov3-Android with 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 #10
Source File: Core.java    From FTCVision with 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 #11
Source File: PreImageUtilsTests.java    From super-cloudops with 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 #12
Source File: Imgproc.java    From MOAAP with 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 #13
Source File: Feature2D.java    From FaceDetectDemo with 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 #14
Source File: Core.java    From OpenCV-AndroidSamples with 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 #15
Source File: Features2d.java    From OpenCvFaceDetect with 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 #16
Source File: Test.java    From classchecks with 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 #17
Source File: Subdiv2D.java    From FTCVision with 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 #18
Source File: Converters.java    From LicensePlateDiscern with 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 File: Frame.java    From ShootOFF with 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
Source File: KalmanFilter.java    From Form-N-Fun with MIT License 3 votes vote down vote up
public  Mat get_errorCovPre()
{
    
    Mat retVal = new Mat(get_errorCovPre_0(nativeObj));
    
    return retVal;
}
 
Example #21
Source File: Core.java    From react-native-documentscanner-android with MIT License 3 votes vote down vote up
public static double determinant(Mat mtx)
{
    
    double retVal = determinant_0(mtx.nativeObj);
    
    return retVal;
}
 
Example #22
Source File: Core.java    From ml-authentication with Apache License 2.0 3 votes vote down vote up
public static void mulTransposed(Mat src, Mat dst, boolean aTa, Mat delta, double scale, int dtype)
{
    
    mulTransposed_0(src.nativeObj, dst.nativeObj, aTa, delta.nativeObj, scale, dtype);
    
    return;
}
 
Example #23
Source File: Core.java    From MOAAP with MIT License 3 votes vote down vote up
public static void add(Mat src1, Scalar src2, Mat dst)
{
    
    add_5(src1.nativeObj, src2.val[0], src2.val[1], src2.val[2], src2.val[3], dst.nativeObj);
    
    return;
}
 
Example #24
Source File: Imgproc.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 3 votes vote down vote up
public static void blur(Mat src, Mat dst, Size ksize, Point anchor, int borderType)
{
    
    blur_0(src.nativeObj, dst.nativeObj, ksize.width, ksize.height, anchor.x, anchor.y, borderType);
    
    return;
}
 
Example #25
Source File: Imgproc.java    From SimpleDocumentScanner-Android with MIT License 3 votes vote down vote up
public static void filter2D(Mat src, Mat dst, int ddepth, Mat kernel, Point anchor, double delta, int borderType)
{
    
    filter2D_0(src.nativeObj, dst.nativeObj, ddepth, kernel.nativeObj, anchor.x, anchor.y, delta, borderType);
    
    return;
}
 
Example #26
Source File: Imgproc.java    From react-native-documentscanner-android with MIT License 3 votes vote down vote up
public static void distanceTransformWithLabels(Mat src, Mat dst, Mat labels, int distanceType, int maskSize)
{
    
    distanceTransformWithLabels_1(src.nativeObj, dst.nativeObj, labels.nativeObj, distanceType, maskSize);
    
    return;
}
 
Example #27
Source File: Calib3d.java    From android-object-distance with Apache License 2.0 3 votes vote down vote up
/**
* <p>Computes an RQ decomposition of 3x3 matrices.</p>
*
* <p>The function computes a RQ decomposition using the given rotations. This
* function is used in "decomposeProjectionMatrix" to decompose the left 3x3
* submatrix of a projection matrix into a camera and a rotation matrix.</p>
*
* <p>It optionally returns three rotation matrices, one for each axis, and the
* three Euler angles in degrees (as the return value) that could be used in
* OpenGL. Note, there is always more than one sequence of rotations about the
* three principle axes that results in the same orientation of an object, eg.
* see [Slabaugh]. Returned tree rotation matrices and corresponding three Euler
* angules are only one of the possible solutions.</p>
*
* @param src 3x3 input matrix.
* @param mtxR Output 3x3 upper-triangular matrix.
* @param mtxQ Output 3x3 orthogonal matrix.
*
* @see <a href="http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#rqdecomp3x3">org.opencv.calib3d.Calib3d.RQDecomp3x3</a>
*/
   public static double[] RQDecomp3x3(Mat src, Mat mtxR, Mat mtxQ)
   {

       double[] retVal = RQDecomp3x3_1(src.nativeObj, mtxR.nativeObj, mtxQ.nativeObj);

       return retVal;
   }
 
Example #28
Source File: TrainData.java    From MOAAP with MIT License 3 votes vote down vote up
public  Mat getTestNormCatResponses()
{
    
    Mat retVal = new Mat(getTestNormCatResponses_0(nativeObj));
    
    return retVal;
}
 
Example #29
Source File: Calib3d.java    From Camdroid with Apache License 2.0 3 votes vote down vote up
public static Mat findEssentialMat(Mat points1, Mat points2, double focal, Point pp, int method, double prob, double threshold, Mat mask)
{
    
    Mat retVal = new Mat(findEssentialMat_0(points1.nativeObj, points2.nativeObj, focal, pp.x, pp.y, method, prob, threshold, mask.nativeObj));
    
    return retVal;
}
 
Example #30
Source File: Imgproc.java    From OpenCV-AndroidSamples with MIT License 3 votes vote down vote up
public static Mat getDefaultNewCameraMatrix(Mat cameraMatrix)
{
    
    Mat retVal = new Mat(getDefaultNewCameraMatrix_1(cameraMatrix.nativeObj));
    
    return retVal;
}