OPCV000

Introduction to OpenCV

Content

  • Introduction
  • Code
  • Demo

Introduction

An interesting "Hello World" in OpenCV. It invokes the camera and recognizes hands. Then, it uses the coordinates of these nodes in hands to draw the real time hands frameworks.

Code

Here comes the code:

import cv2
import mediapipe as mp



cap=cv2.VideoCapture(0)

mpHands= mp.solutions.hands
hands = mpHands.Hands()

mpDraw= mp.solutions.drawing_utils

while True:
    ret, img =cap.read()
    if ret: 
        imgRGB=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
        result=hands.process(imgRGB)
        #print(result.multi_hand_landmarks)
        if result.multi_hand_landmarks:
            for handLms in result.multi_hand_landmarks:
                mpDraw.draw_landmarks(img,handLms,mpHands.HAND_CONNECTIONS)
        cv2.imshow('img',img)
    
    if cv2.waitKey(1) == ord('q'):
        break
#### Demo

https://www.bilibili.com/video/BV1w44y1j7y3