Java Code Examples for org.opencv.core.Mat#depth()
The following examples show how to use
org.opencv.core.Mat#depth() .
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: TestUtils.java From go-bees with GNU General Public License v3.0 | 6 votes |
/** * Checks if two OpenCV Mats are equal. * The matrices must be equal size and type. * Floating-point mats are not supported. * * @param expected expected mat. * @param actual actual mat. * @return true if they are equal. */ private static boolean equals(Mat expected, Mat actual) { if (expected.type() != actual.type() || expected.cols() != actual.cols() || expected.rows() != actual.rows()) { throw new UnsupportedOperationException( "Can not compare " + expected + " and " + actual); } else if (expected.depth() == CvType.CV_32F || expected.depth() == CvType.CV_64F) { throw new UnsupportedOperationException( "Floating-point mats must not be checked for exact match."); } // Subtract matrices Mat diff = new Mat(); Core.absdiff(expected, actual, diff); // Count non zero pixels Mat reshaped = diff.reshape(1); // One channel int mistakes = Core.countNonZero(reshaped); // Free reshaped.release(); diff.release(); // Check mistakes return 0 == mistakes; }
Example 2
Source File: Filters.java From OptimizedImageEnhance with MIT License | 5 votes |
private static Mat convertTo(Mat mat, int depth) { if (mat.depth() == depth) { return mat; } Mat result = new Mat(); mat.convertTo(result, depth); return result; }
Example 3
Source File: Filters.java From ImageEnhanceViaFusion with MIT License | 5 votes |
private static Mat convertTo(Mat mat, int depth) { if (mat.depth() == depth) { return mat; } Mat result = new Mat(); mat.convertTo(result, depth); return result; }
Example 4
Source File: PatchGenerator.java From OpenTLDAndroid with Apache License 2.0 | 5 votes |
/** * * @param image * @param T * @param patch OUTPUT * @param patchSize */ void generate(final Mat image, final Mat T, Mat patch, Size patchSize, final RNG rng){ patch.create( patchSize, image.type() ); if( backgroundMin != backgroundMax ) { Core.randu(patch, backgroundMin, backgroundMax); // TODO if that null scalar OK or should it be new Scalar(0) ? Imgproc.warpAffine(image, patch, T, patchSize, Imgproc.INTER_LINEAR, Imgproc.BORDER_TRANSPARENT, null); } else { Imgproc.warpAffine(image, patch, T, patchSize, Imgproc.INTER_LINEAR, Imgproc.BORDER_CONSTANT, new Scalar(backgroundMin)); } int ksize = randomBlur ? rng.nextInt() % 9 - 5 : 0; if( ksize > 0 ) { ksize = ksize * 2 + 1; Imgproc.GaussianBlur(patch, patch, new Size(ksize, ksize), 0, 0); } if( noiseRange > 0 ) { final Mat noise = new Mat(patchSize, image.type()); int delta = (image.depth() == CvType.CV_8U ? 128 : (image.depth() == CvType.CV_16U ? 32768 : 0)); Core.randn(noise, delta, noiseRange); // TODO this was different !! Core.addWeighted(patch, 1, noise, 1, -delta, patch); // if( backgroundMin != backgroundMax ) // addWeighted(patch, 1, noise, 1, -delta, patch); // else // { // for( int i = 0; i < patchSize.height; i++ ) // { // uchar* prow = patch.ptr<uchar>(i); // const uchar* nrow = noise.ptr<uchar>(i); // for( int j = 0; j < patchSize.width; j++ ) // if( prow[j] != backgroundMin ) // prow[j] = saturate_cast<uchar>(prow[j] + nrow[j] - delta); // } // } } }