[英]raspberry pi pico (micropython) throws ImportError
如果我使用 python 在 VsCode 中運行此代碼,它工作得很好,但如果我使用 MicroPython 運行它,我會收到錯誤ImportError: no module named 'cv2'
#from machine import ADC,PWM,Pin
import cv2
import mediapipe as mp
LandMarks = mp.solutions.drawing_utils
HandsModule = mp.solutions.hands
cam = cv2.VideoCapture(0)
forcc = cv2.VideoWriter_fourcc('m','p','4','v')
with HandsModule.Hands(static_image_mode = False,min_detection_confidence=0.7,min_tracking_confidence= 0.7,max_num_hands=2) as hands:
while True:
ret,frame = cam.read()
frame1 = cv2.resize(frame,(640,480))
results = hands.process(cv2.cvtColor(frame1,cv2.COLOR_BGR2RGB))
if results.multi_hand_landmarks != None:
for handlandmarks in results.multi_hand_landmarks:
LandMarks.draw_landmarks(frame1,handlandmarks,HandsModule.HAND_CONNECTIONS)
cv2.imshow('img',frame1)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
注意:我剛剛評論了導入機器,因為 python 不將其識別為 MicroPython
正如@Klaus D. 所說,Pico 是微控制器,而不是計算機。 因此,它不能運行這樣的 python 程序。 但是,它可以運行 micropython。 如果你想運行你指定的腳本,你需要使用不同的樹莓派。 如果您希望使用 Pico W(我不推薦),正如 Mark Setchell 所說,您將需要進行額外的處理(在您的筆記本電腦上),這會增加額外的復雜性。
最簡單的方法是只使用 Raspberry Pi Zero W 或 Raspberry Pi 4(而不是使用 micropython),這樣您就可以非常直接地運行指定的腳本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.