-1

I keep running into this error and can't fix it. I spoke with many people and they are not sure what to do. My code is below. This is very simple code that should open my webcam and display the live video. I am using python 3.8.0 on a M1 Mac 64 bit Ventura 13.2 using VsCode with the latest version of openCv, Mediapipe, and numpy. I have tried different IDE's and no luck.

import cv2
import mediapipe as mp
import numpy as np

mp_drawing = mp.solutions.drawing_utils
mp_pose = mp.solutions.pose

#VIDEO FEED
cap = cv2.VideoCapture(0)
while cap.isOpened():
    ret, frame = cap.read()
    cv2.imshow('Mediapipe Feed', frame)
    
    if cv2.waitKey(10) & 0xFF == ord('q'):
        break
        
cap.release()
cv2.destroyAllWindows()

I got this code to work the first time I ran it. I ran it a few times, then connected my laptop via HDMI to a TV that has a camera built into it and then disconnected my laptop from the TV and now my code doesn't work. I think it has something to do with not being able to find the camera on my laptop but I can't figure it out. Any help would be great! I have tried changing the argument inside the .VideoCapture() from -10 to 10 and still no luck.

Markus
  • 5,976
  • 5
  • 6
  • 21
Skrilzz
  • 1
  • 1
  • Please provide a little bit more debug information. It seems that the mediapipe code isn't used in your example. So it would be more clear if you remove those lines. In this case the error message probably won't contain anything about mediapipe. So what is the exact error message? What is the result of `cap.isOpened()`? What is the result of `ret`? – Markus Jan 26 '23 at 14:16
  • Hi Markus, yes for this code I am not using Mediapipe. I should have removed it, sorry. The error message I am getting is "zsh: illegal hardware instruction" followed by the path to where this test document is saved on my computer. What is happening is all the code above the cap = cv2.VideoCapture(0) is running perfectly fine. When it gets to this line, the computer picks up an error and stops the program, and returns that zsh error. ret and the entire while loop is not running because the computer is not getting to that code. Any suggestions? Thanks for your help!! – Skrilzz Jan 28 '23 at 21:38
  • Sorry I'm not using Mac. Similar question: https://stackoverflow.com/q/65383338/18667225 – Markus Jan 29 '23 at 18:04

2 Answers2

0

This seems to be a problem caused by the M1 CPU with macOS. You need to compile OpenCV by yourself or download a compiled OpenCV by others for M1. Then the mediapipe for sure. Welcome to the world of Mx CPU.

vscv
  • 86
  • 4
0

I had conflicting packages. I installed a bunch of packages via homebrew and pip3. I installed everything I am not using or going to use and that solved the issue. OpenCv works now, but I can't install mediapipe or mediapipe-silicon for my M1 mac. If I fix this, I will let everyone know.

Skrilzz
  • 1
  • 1
  • This illegal instruction problem is produced by installing x86_64 packages instead of ARM ones, even with Rosetta emulation it does not support AVX instructions and some software just crashes. Prefer ARM binaries for everything – Dr. Snoopy Jan 31 '23 at 17:10