0

Good morning to everyone.

I am developing an application in Android environment that captures frames from a video stream, in order to process them, and then shows the processed frames on screen. This application, if the device has two cameras, allows the switch between front camera and back camera.

The switching between cameras worked until I created the background processing thread (asynktask). The program works correctly with the introduction and execution of the thread, but if I try to change the camera, it crashes. In the asynktask I do only the following operations: resizing the frame, calculating some points on the resized frame, scaling the points basing on the size of the original frame, showing the original frame on screen with recalculated points printed on it.

If I try to do the switching, the error I get in logcat is:

07-02 11:14:41.649: ERROR/AndroidRuntime(16778): FATAL EXCEPTION: pool-1-thread-3
    java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:299)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
    at java.util.concurrent.FutureTask.run(FutureTask.java:239)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
    at java.lang.Thread.run(Thread.java:856)
    Caused by: CvException [org.opencv.core.CvException: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/imgwarp.cpp:1723: error: (-215) ssize.area() > 0 in function void cv::resize(cv::InputArray, cv::OutputArray, cv::Size, double, double, int)
    ]
    at org.opencv.imgproc.Imgproc.resize_0(Native Method)
    at org.opencv.imgproc.Imgproc.resize(Imgproc.java:8461)
    at com.micaela.myapp.MainActivity$ExtractFeaturesTask.scaleImage(MainActivity.java:764)
    at com.micaela.myapp.MainActivity$ExtractFeaturesTask$1.handleMessage(MainActivity.java:678)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at com.micaela.myapp.MainActivity$ExtractFeaturesTask.doInBackground(MainActivity.java:736)
    at com.micaela.myapp.MainActivity$ExtractFeaturesTask.doInBackground(MainActivity.java:649)
    at android.os.AsyncTask$2.call(AsyncTask.java:287)
    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
user140888
  • 609
  • 1
  • 11
  • 31

2 Answers2

0

I did a bit of research on the CvException error in the logcat. It appears to be a problem with the way you're manipulating the image. Is the image getting passed to the ASync? After verifying that check to make sure all your parameters are correct.

SonicWind
  • 58
  • 1
  • 6
  • I have only added a control to check that image.size.area() > 0 (the error that is shown in logcat). Now if I switch the camera, the app doesn't crash, but only blocks (as freezed). The very strange thing is that, while it's freezed, if I re-press switching button, the switching starts to work. – user140888 Jul 02 '13 at 09:52
  • Sounds like it starts doing a lot of work when you first press switch. Stick in a couple of Log.i 's for debug and see if anything loops or starts prematurely. – SonicWind Jul 02 '13 at 10:52
0

Async task should not work directly with the byte[] received in onPreviewCallback(). If you copy the pixels to a temporary array and pass it to AsyncTask, the exception will go away.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307