Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In the python file OpenCV isnot able to read the image, though the location is correct #335

Closed
sayantan99 opened this issue Jul 6, 2020 · 3 comments

Comments

@sayantan99
Copy link

com.chaquo.python.PyException: error: OpenCV(4.1.2) /home/smith/git/chaquo/python/server/pypi/packages/opencv-python/build/4.1.2.30/cp38-cp38-android_21_arm64_v8a/src/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

@mhsmith
Copy link
Member

mhsmith commented Jul 6, 2020

Please post the full stack trace and the relevant section of your code.

@sayantan99
Copy link
Author

The image is in the python folder of the app, along with the python file.
Code:(Python)
import cv2
from os.path import dirname, join
from android.os import Environment
def test():
src = cv2.imread("sam.jpg", 1 )
grayScale = cv2.cvtColor( src, cv2.COLOR_RGB2GRAY )
kernel = cv2.getStructuringElement(1,(17,17))

StackTrace:
E/cv::error(): OpenCV(4.1.2) Error: Assertion failed (!_src.empty()) in cvtColor, file /home/smith/git/chaquo/python/server/pypi/packages/opencv-python/build/4.1.2.30/cp38-cp38-android_21_arm64_v8a/src/opencv/modules/imgproc/src/color.cpp, line 182
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.chao, PID: 26627
com.chaquo.python.PyException: error: OpenCV(4.1.2) /home/smith/git/chaquo/python/server/pypi/packages/opencv-python/build/4.1.2.30/cp38-cp38-android_21_arm64_v8a/src/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

    at <python>.ops.test(ops.py:12)
    at <python>.chaquopy_java.call(chaquopy_java.pyx:281)
    at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrows(chaquopy_java.pyx:253)
    at com.chaquo.python.PyObject.callAttrThrows(Native Method)
    at com.chaquo.python.PyObject.callAttr(PyObject.java:209)
    at com.example.open.MainActivity$1.onClick(MainActivity.java:40)
    at android.view.View.performClick(View.java:7870)
    at android.widget.TextView.performClick(TextView.java:14970)
    at android.view.View.performClickInternal(View.java:7839)
    at android.view.View.access$3600(View.java:886)
    at android.view.View$PerformClick.run(View.java:29363)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:7814)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

@mhsmith
Copy link
Member

mhsmith commented Jul 6, 2020

As I already told you in #301, to open files in the same directory as the Python file you need to use the technique from #144.

@mhsmith mhsmith closed this as completed Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants