Python / OpenCV网络摄像头向后移动

时间:2014-03-09 19:15:40

标签: python opencv webcam

我不确定问题是什么,但是当我在网络摄像头上移动时,它会抓住我的脸,但它不是我的动作的镜子,它是向后/倒置的。

有谁知道如何解决这个问题?

def网络摄像头(网络摄像头,分类器,downScale):

    if webcam.isOpened():
            rval, frame = webcam.read()
    else:
            rval = False

    while rval:
            # detect faces and draw bounding boxes
            minisize = (frame.shape[1]/downScale,frame.shape[0]/downScale)
            miniframe = cv2.resize(frame, minisize)
            faces = classifier.detectMultiScale(miniframe)
            for f in faces:
                    x, y, w, h = [ v*downScale for v in f ]
                    cv2.rectangle(frame, (x,y), (x+w,y+h), (0,0,255))

            cv2.putText(frame, "Press ESC to close.", (5, 25),
                                    cv2.FONT_HERSHEY_SIMPLEX, 1.0, (255,255,255))
            cv2.imshow("Face Crop", frame)

            # get next frame
            rval, frame = webcam.read()

            key = cv2.waitKey(10)
            if key in [27, ord('Q'), ord('q')]: # exit on ESC
                    break   

2 个答案:

答案 0 :(得分:1)

相机不是镜子。

但您可以轻松地flip()表现得像镜子一样:

rval, frame = webcam.read()
frame = cv2.flip(frame,1)

答案 1 :(得分:0)

rval, frame = webcam.read()

frame = cv2.flip(frame,0)

cv2.flip() 参数中,如果要在 y 轴上翻转,请尝试使用 0,如果要在 x 轴上翻转,请尝试使用 1,如果要在两个轴上都翻转,请尝试使用 -1。

@berak flip()

提供的文档中明确提到了这一点