Unknown crash when getting a double[] from a Mat
I have been working with the OpenCV library (version 3.30) with Android, and occasionally there has been a crash when trying to retrieve the color information from a HSV image Mat. I've copied the logcat log below:
/data/app/com.example.administrator.grapeyield-2/lib/arm64/libopencv_java3.so (Java_org_opencv_core_Mat_nGet+2904) 03-08 09:44:04.359 3165-3165/? A/DEBUG: #01 pc 0000000000aa1220 /data/app/com.example.administrator.grapeyield-2/oat/arm64/base.odex (offset 0x62f000) (double[] org.opencv.core.Mat.nGet(long, int, int)+148) 03-08 09:44:04.359 3165-3165/? A/DEBUG: #02 pc 0000000000aaa544 /data/app/com.example.administrator.grapeyield-2/oat/arm64/base.odex (offset 0x62f000) (double[] org.opencv.core.Mat.get(int, int)+88) 03-08 09:44:04.359 3165-3165/? A/DEBUG: #03 pc 000000000094565c /data/app/com.example.administrator.grapeyield-2/oat/arm64/base.odex (offset 0x62f000) (java.util.List com.example.administrator.grapeyield.utilities.CSVContentFormatter.getHueListOfBerry(org.opencv.core.Mat, org.opencv.core.Mat, int, int)+1232) 03-08 09:44:04.359 3165-3165/? A/DEBUG: #04 pc 0000000000917888 /data/app/com.example.administrator.grapeyield-2/oat/arm64/base.odex (offset 0x62f000) (void com.example.administrator.grapeyield.activities.White_wine_analysis_Activity.houghcircle_fiveranges(android.graphics.Bitmap)+45276) 03-08 09:44:04.359 3165-3165/? A/DEBUG: #05 pc 0000000000926528 /data/app/com.example.administrator.grapeyield-2/oat/arm64/base.odex (offset 0x62f000) (void com.example.administrator.grapeyield.activities.White_wine_analysis_Activity.volumedistPressed()+412) 03-08 09:44:04.359 3165-3165/? A/DEBUG: #06 pc 00000000008fb118 /data/app/com.example.administrator.grapeyield-2/oat/arm64/base.odex (offset 0x62f000) (void com.example.administrator.grapeyield.activities.White_wine_analysis_Activity$volumeDistTask.onPostExecute(java.lang.Void)+76) 03-08 09:44:04.359 3165-3165/? A/DEBUG: #07 pc 00000000008fb068 /data/app/com.example.administrator.grapeyield-2/oat/arm64/base.odex (offset 0x62f000) (void com.example.administrator.grapeyield.activities.White_wine_analysis_Activity$volumeDistTask.onPostExecute(java.lang.Object)+108)
My understanding of the log is that the error is occurring in the "getHueListOfBerry" method, which is below:
public static List<Integer> getHueListOfBerry(Mat circles, Mat oriImage, int row, int col){
List<Integer> hueList = new ArrayList<Integer>();
try {
Mat hsvImage = new Mat();
Imgproc.cvtColor(oriImage, hsvImage, Imgproc.COLOR_BGR2HSV);
int radius = MatUtils.getRadius(circles, row, col);
Point point = MatUtils.getPoint(circles, row, col);
int jStart = (int) (point.x - radius);
int kStart = (int) (point.y - radius);
int jEnd = (int) (point.x + radius);
int kEnd = (int) (point.y + radius);
if (jStart < 0) {
kStart = 0;
}
if (kStart < 0) {
jStart = 0;
}
if (jEnd > oriImage.rows()) {
jEnd = oriImage.rows() - 1;
}
if (kEnd > oriImage.cols()) {
kEnd = oriImage.cols() - 1;
}
for (int j = jStart; j < jEnd; j++) {
for (int k = kStart; k < kEnd; k++) {
if (hsvImage.get(j, k) != null) {
double pixel_h = oriImage.get(j, k)[0];
double pixel_s = oriImage.get(j, k)[1];
double pixel_v = oriImage.get(j, k)[2];
if ((pixel_h != 0) || (pixel_s != 0) || pixel_v != 0) {
if (ColourUtils.isPointInCircle(point.x, point.y, radius, j, k)) {
if ((pixel_h != 0)) {
int pixIndex = (int) pixel_h;
hueList.add(pixIndex);
}
}
}
}
}
}
} catch(Exception e){
Log.e("errorCSVhuelist", e.toString());
}
return hueList;
}
For the life of me I haven't ...
"For the life of me I haven't been able to find out what's been going on"
obviously so. . 100% of that is irrelevant, and we cannot see ny code here, that lead to it
Have edited the question to include the method where the error is occurring.
you really expect us to remote debug that ?
just stop using put() and get() calls per pixel
Is there another way to extract the hue values? For the app I'm working on, I'm required to to extract the hue from each pixel contained in a circle.
one of your get() calls is out of range
sorry to say so, but as it is now, we canot help you with it, above code is as incomplete as the errormessages
use a debugger, try to find out where it happens, try to make a small reproducable testcase from that. then we can help you
Hi, apologies for the late reply, I just arrived at work. Thanks for your continued attention to this issue. I have been using the standard Android Studio debugger and I surrounded the relevant code with a try/catch statement, but the error message copied into the question above is the only caught Exception. You have given me some ideas about what the problem might be, I'll do some tests and post the solution if I find it