コード例 #1
0
def start(file_path, port):

    cap = cv2.VideoCapture(file_path)

    while (True):

        # Capture frame-by-frame
        ret, frame = cap.read()

        if not ret:
            break

        # Our operations on the frame come here
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

        frameData = cv2.imencode('.jpg', frame)[1].tostring()

        tmpTime = time.time()
        r = requests.post("http://localhost:" + port,
                          headers={'Content-Type': 'application/octet-stream'},
                          data=frameData)
        fps = int(1 / (time.time() - tmpTime))

        jsonPose = json.loads(r.text)
        poses = [Pose2D.build_from_JSON(p['pose_2d']) for p in jsonPose]

        ids = [p['id'] for p in jsonPose]

        frame = Drawer.draw_scene(frame, poses, ids, fps,
                                  cap.get(cv2.CAP_PROP_POS_FRAMES))

        frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)

        cv2.imshow('frame', frame)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

        if cv2.waitKey(33) == ord(' '):
            curr_frame = cap.get(cv2.CAP_PROP_POS_FRAMES)
            cap.set(cv2.CAP_PROP_POS_FRAMES, curr_frame + 30)

    # When everything done, release the capture
    cap.release()
    cv2.destroyAlWindows()
コード例 #2
0
def main():
    capture = cv2.VideoCapture('http://172.19.10.149/axis-cgi/mjpg/video.cgi')
    k = 0
    #fourcc = cv2.cv.CV_FOURCC(*'XVID')
    #video_writer = cv2.VideoWriter("output_cam6.avi", fourcc, 20, (768, 576))
    while (capture.isOpened()):
        ret, frame = capture.read()
        k += 1
        print k
        cv2.imwrite('frame_%d.jpg' % k, frame)
        if ret:
            #video_writer.write(frame)
            cv2.imshow('Video Stream cam 6', frame)
        else:
            break

    capture.release()
    #video_writer.release()
    cv2.destroyAlWindows()
コード例 #3
0
while 1:
    ret, img = cam.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = faceDetect.detectMultiScale(gray, 1.3, 5)
    for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2)
        id, conf = rec.predict(gray[y:y + h, x:x + w])
        if (id == 1):
            webbrowser.get(pathOfWeb).open_new_tab(website)
            cam.release()
            cv2.destroyAllWindows()
        elif (id == 2):
            id = 'ShahRukKhan'
        elif (id == 3):
            id = 'Saloni'
        elif (id == 4):
            id = 'Raxxxx Dii'
        elif (id == 5):
            id = 'Mr. Beck'
        elif (id == 6):
            id = 'Mr. Viral'

        else:
            id = "User Not Authorised"
    #   cv2.putText(img,str(id),(x,y+h), font, 2,(255,0,0),3);
    #cv2.imshow("Face",img)
    if (cv2.waitKey(1) == 27):
        break
cam.release()
cv2.destroyAlWindows()