I have a python3 script on my computer that I can run with python3 motion_detection.py
and that works, I tried to use it on my Raspberry and something fails with message Illegal instruction
. The line that throws this error is: frame = imutils.resize(frame, width=500)
Here is the minimalist sample of code:
import imutils
import cv2
frame = cv2.imread('test.jpg')
frame = imutils.resize(frame, width=500)
I'm sure that frame is not None because I tried to save it and it worked.
I'm a bit confused because there is no more explaination that Illegal instruction
I checked the version of imutils that is the same on my computer that on the Raspberry (0.4.6)
Try changing the line frame = imutils.resize(frame, width=500)
to frame = imutils.resize(frame, width=500, inter=cv2.INTER_NEAREST)
. Does that work?
It seems to be a problem with the imutils implementation of resize with certain interpolation methods. The default interpolation method, specified as INTER_LINEAR
, causes the Illegal instruction
error on the RPi Zero. But if you override the default to a non-problematic interpolation method, it may work! I tested each of the options and found each of the following interpolation methods to run successfully on my RPi Zero : INTER_NEAREST, INTER_CUBIC, INTER_LANCZOS4
.
Let me know if this works for you. I wish I had more details on the why, but have so far poked around the imutils source code to no avail.