# pip install cvzone
# pip install opencv-contrib-python

from cvzone.HandTrackingModule import HandDetector
import cv2
cap = cv2.VideoCapture(1)
detector = HandDetector(detectionCon=0.5, maxHands=2)
while True:
    success, img = cap.read()
    img = cv2.flip(img, 1)
    img = detector.findHands(img)
    lmList, bbox = detector.findPosition(img, draw=False)
    if lmList:
        myHandType = detector.handType()
        cv2.putText(img, myHandType, (50, 50), cv2.FONT_HERSHEY_PLAIN, 2,
                    (0, 255, 0), 2)
    cv2.imshow("Image", img)
    cv2.waitKey(1)
Esempio n. 2
0

def resizeimg(image):
    h, w = image.shape[:2]
    if h < w:
        img = cv2.resize(image,
                         (dW, math.floor(h / (w / dW))))  #有小數點無條件捨去,負數就進位
    else:
        img = cv2.resize(image, (math.floor(w / (h / dH)), dH))
    return img


img = resizeimg(cv2.imread('/content/drive/MyDrive/lcc/fcu/hand1.jpg'))
detector = HandDetector(mode=False, maxHands=2)  #動態追蹤True
img1 = detector.findHands(img)
cv2_imshow(img)

myHandType = detector.handType
print(myHandType)

ImList, bboxInfo = detector.findPosition(img)
print(ImList)
print(bboxInfo)

from cvzone.PoseModule import PoseDetector

img = resizeimg(cv2.imread('/content/drive/MyDrive/lcc/fcu/pose1.jpg'))
pose = PoseDetector()
img = pose.findPose(img)
cv2_imshow(img)
Esempio n. 3
0
cvzone modülü 1.5 sürümü ve üstünde findPosition kaldırıldı
"""
import cv2
from cvzone.HandTrackingModule import HandDetector

cap = cv2.VideoCapture(0)  #kamera ID numarası
detector = HandDetector(detectionCon=0.5,
                        maxHands=2)  #max el  sayısı ve el alglama hassasiyeti
I = []  #parmakların konumunu tutmak için

while True:
    _, img = cap.read()  #kamera okuma
    img = cv2.flip(img, 1)  #resmi aynalama
    img = cv2.resize(img, (1280, 640))  #ekran boyutlarını ayarlama
    img = detector.findHands(img)  #elleri algılama
    I, box = detector.findPosition(
        img)  #parmakları algılama (20 nokta algılama)

    if I:
        #x ve y  konumlarını alma ilk parametre nokta ikincisi x veya y demek
        f = detector.fingersUp()
        x1 = I[4][0]
        y1 = I[4][1]
        x2 = I[8][0]
        y2 = I[8][1]

        #belirtilen konumları cembere alma ve cizgi cekme
        cv2.circle(img, (x1, y1), 7, (0, 255, 255), 2)
        cv2.circle(img, (x2, y2), 7, (0, 255, 255), 2)
        cv2.line(img, (x1, y1), (x2, y2), (255, 0, 255), 2)
    #görüntüleme işlemi
    cv2.imshow("Img", img)