Opencv is a cross platform computer vision library based on BSD license (open source), which can run on Linux, windows and Mac OS operating systems. It is lightweight and efficient, which is composed of a series of C functions and a small number of C + + classes. It also provides the interfaces of Java, python, ruby, MATLAB and other languages, and realizes many general algorithms in image processing and computer vision
When opencv is called with Java JNI, it is OK to recognize a single picture. When there are a lot of pictures, an error will be reported
OpenCV Error: Insufficient memory (Failed to allocate 411068927 bytes) in cv::OutOfMemoryError, file opencv\modules\core\src\alloc.cpp, line 52 OpenCV Error:
System.out.println("\nRunning Template Matching");
Mat img = Highgui.imread(inFile);
Mat templ = Highgui.imread(templateFile);
///Create the result matrix
int result_cols = img.cols() - templ.cols() + 1;
int result_rows = img.rows() - templ.rows() + 1;
Mat result = new Mat(result_rows, result_cols, CvType.CV_64FC1);
///Do the Matching and Normalize
Imgproc.matchTemplate(img, templ, result, match_method);
Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
///Localizing the best match with minMaxLoc
MinMaxLocResult mmr = Core.minMaxLoc(result);
Point matchLoc;
if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {
matchLoc = mmr.minLoc;
} else {
matchLoc = mmr.maxLoc;
}
///Show me what you got
Core.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),
matchLoc.y + templ.rows()), new Scalar(0, 255, 0));
// Save the visualized detection.
System.out.println("Writing "+ outFile);
Highgui.imwrite(outFile, img);
JNI calls native’s C + + method because of memory overflow, but it didn’t release the object. Display call:
img.release();
templ.release();
result.release();
Solve it. C + + is the trouble of actively releasing referenced objects
Similar Posts:
- Python OpenCV TypeError: integer argument expected, got float
- [record a problem] Linux + opencv + cuvid decodes 1080p video. When using CUDA kernel function, it will crash
- [Solved] Lego-loam Error: opencv fatal error: cv.h: No such file or directory
- AttributeError: module ‘cv2’ has no attribute ‘CV_HAAR_SCALE_IMAGE’
- [Solved] Ubuntu 18.04 Compile opencv-3.4.16 Error: “c++: internal compiler error: Killed (program cc1plus)”
- Problem solved successfully in Python: attributeerror: ‘module’ object has no attribute ‘loadimage‘
- Error reporting on data type and matrix dimension of eigen
- Python OpenCV BUG: all the input arrays must have same number of dimensions
- AttributeError: module ‘cv2’ has no attribute ‘SIFT’ [How to Solve]
- Ubuntu 18.04: How to Install & Configure Opencv 4.2.0