0
我已經看過how to get sub image by using OpenCV in java api得到一個子圖像,但這並沒有幫助使用OpenCV的Java的
我很好奇如何創建,我已經從文件加載的墊圖像的子圖像。當我運行:
crop = img.submat(405, 450, 280, 335);
我得到:
OpenCV Error: Assertion failed (m.dims >= 2) in cv::Mat::Mat, file ..\..\..\..\opencv\modules\core\src\matrix.cpp, line 269
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matrix.cpp:269: error: (-215) m.dims >= 2 in function cv::Mat::Mat
]
at org.opencv.core.Mat.n_submat_rr(Native Method)
at org.opencv.core.Mat.submat(Mat.java:2270)
at Parking.WebCommunications.processImage(WebCommunications.java:54)
at Parking.WebCommunications.<init>(WebCommunications.java:27)
at Parking.App.main(App.java:19)
我似乎無法找出爲什麼發生這種情況。當我運行什麼似乎是一個類似一塊在它正常工作在圖像上Python代碼...但我需要的java工作...
編輯:
Range xRange = new Range(405, 450);
Range yRange = new Range(280, 355);
Mat crop;
Mat blur = null;
System.loadLibrary("opencv_java2411");
//Load image from file
Mat img = Highgui.imread("/Users/\"User name\"/git/SE300/JavaWorkspace/ParkingLotApp/src/main/resources/bottomOpen.JPG");
//LOOP:
//Crop to the Nth spot: cropN = img[y:y+h, x:x+w]
System.out.println(img.rows());
System.out.println(img.cols());
crop = img.submat(405, 450, 280, 335);
前行'作物= img.submat(405,450,280,335);'嘗試打印和調試'img.rows'和'img.cols'以檢查圖像是否被正確加載。 – ZdaR
@ZdaR我真的這個,它打印出兩個都爲0。有沒有添加照片的特定方式?我添加了上面的代碼的其餘部分: – Ian
我很愚蠢,不知道絕對路徑在哪裏,但是當我做到了「src/main/resources/bottomOpen.JPG」它工作....謝謝哈哈 – Ian