On UI Thread:
AsyncCaller asyncCaller = new AsyncCaller();
asyncCaller.doInBackground();
In AsyncTask: @Override protected Void doInBackground(Void... params) {
Mat orignal = new Mat(image1.getHeight(), image1.getWidth(), CvType.CV_8UC3);
Mat v_blur = new Mat(image1.getHeight(), image1.getWidth(), CvType.CV_8UC3);
Utils.bitmapToMat(image1, orignal);
Imgproc.GaussianBlur(orignal, v_blur, new Size(3, 3), 0);
// blur completed
Mat to_zero = new Mat(image1.getHeight(), image1.getWidth(), CvType.CV_8UC4);
Imgproc.threshold(v_blur, to_zero, 100, 100, Imgproc.THRESH_TOZERO);
Bitmap bmp = image1;
Log.e("background", "in bg");
Utils.bitmapToMat(bmp, to_zero);
for (int j = 0; j < bmp.getWidth(); j++) {
for (int i = 0; i < bmp.getHeight(); i++) {
int pixelValue = bmp.getPixel(j, i);
int red = Color.red(pixelValue);
int green = Color.green(pixelValue);
int blue = Color.blue(pixelValue);
if (red > 10 && blue > 10 && green > 10) {
int led_bulb = checkForAlreadyExistance(j, i);
if (led_bulb == -1) {
int start_x = getMinValue(j);
int start_y = getMinValue(i);
int end_x = getMaxValue(j, bmp.getWidth());
int end_y = getMaxValue(i, bmp.getHeight());
Log.e("crop_values", start_x + " " + end_x + " " + start_y + " " + end_y);
LEDs.add(new LedBoundingBox(LED++, end_x, start_x, end_y, start_y, 0, 0, 0.0));
} else {
if (j > LEDs.get(led_bulb).inner_x_max) {
LEDs.get(led_bulb).inner_x_max = j;
}
if (j < LEDs.get(led_bulb).inner_x_min) {
LEDs.get(led_bulb).inner_x_min = j;
}
if (i > LEDs.get(led_bulb).inner_y_max) {
LEDs.get(led_bulb).inner_y_max = i;
}
if (i < LEDs.get(led_bulb).inner_y_min) {
LEDs.get(led_bulb).inner_y_min = i;
}
}
}
}
}
Log.e("bgComplete", "complete");
return null;
}
I am working on image processing using android OpenCV library. First I did all this work on UI thread, but faced UI hanging issue. So I shifted it to background thread. But Still I am facing UI hanging issue. Can anyone explain why this happening and any possible solution? Thanks