-2

if i run this code in VsCode with python it works just fine but if i run it with MicroPython i get the error 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

note: i just commented import machine because python doesn't recognize it as MicroPython

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
VLAD 05
  • 5
  • 2

1 Answers1

1

As @Klaus D. said, a Pico is a microcontroller, not a computer. As such, it cannot run such python programs. It can however, run micropython. If you wish to run the script you specified, you need to use a different Raspberry pi. If you wish to use a Pico W (which I would not recommend), As Mark Setchell said, you will need to do extra processing (on your laptop), which adds additional complexity.

The easiest would be to just use a Raspberry Pi Zero W or Raspberry Pi 4 (and not use micropython), which would allow you to run the specified script pretty straightforwardly.