I have come across an error which I guess is very common in OpenCV apps. When I try to run the app, it says "it seems that your device does not support camera(or it is locked)". I have seen this and this and I have already done whatever they have said, like granting camera permission and rebooting the device etc. But still problem persists. I know this problem means that any other app must be using camera and hence it is locked. When I clear the cache of all the apps using camera which might me using camera, then it works but just once. After that same issue. Any solution to this problem?
Thank you.
I have just run into the same problem with OpenCV for Android, and found that going to the phone's Settings -> Apps (or similar) -> Your app -> Permissions and enabling the Camera
permission seems to solve the problem.
Hope this helps.
Update
As noted by @F43nd1r in the comments below, asking the user to update their permissions in the app settings menu should not be done for your own apps. What should be done is to ask the user for permission to access the camera/whatever, as per https://developer.android.com/training/permissions/requesting.html.
I actually received this error in BlueStack but I solved it by going to Task Manager and ending all the processes of BlueStack. Started BlueStack again and it is working perfect. You can do same if you encounter this problem on your phone. Just restart the phone and it will work fine.
Edit org.opencv.android.JavaCameraView.java and search
Szie frameSize = calculateCameraFrameSize(sizes, new JavaCameraSizeAccessor(), width, height);
Replace with follow
Size frameSize;
if(width>height)
{
frameSize = calculateCameraFrameSize(sizes, new JavaCameraSizeAccessor(), width, height);
}
else
{
frameSize = calculateCameraFrameSize(sizes, new JavaCameraSizeAccessor(), height, width);
}
Accordingly to the Android docs:
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.
It means that on new Android devices you also need to request a runtime permission to use, for instance, the camera.
I posted an answer with the piece of code you need to the question you mentioned.
Check this out: https://stackoverflow.com/a/44087946/4398784
Hope it helps!
Changing the line 143 in the JavaCameraView.java
(opencv for android library)
Size frameSize = calculateCameraFrameSize(sizes, new JavaCameraSizeAccessor(), width, height);
to
Size frameSize = new Size(width,height);//calculateCameraFrameSize(sizes, new JavaCameraSizeAccessor(), width, height);
来源:https://stackoverflow.com/questions/29811835/it-seems-that-your-device-does-not-support-camera