Ask Your Question

PatrickT's profile - activity

2017-03-06 01:39:18 -0600 commented answer how to save detected face in opencv

I am sure it will be a similar idea, with a different syntax. If I get a chance I will post the java version

2017-03-06 01:29:55 -0600 answered a question how to save detected face in opencv

Let assume that there is only one face. We can crop the result of the face detection and save it as follows:

import cv2
import sys

cascPath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascPath)

video_capture = cv2.VideoCapture(0)

while True:

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

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv2.cv.CV_HAAR_SCALE_IMAGE
    )

    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    # Display the resulting frame
    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    if cv2.waitKey(1) & 0xFF == ord('c'):
        crop_img = frame[y: y + h, x: x + w] # Crop from x, y, w, h -> 100, 200, 300, 400
        cv2.imwrite("face.jpg", crop_img)

video_capture.release()
cv2.destroyAllWindows()
2017-03-05 23:47:31 -0600 answered a question can not read a video using opencv!

The issue here might well be that Ubuntu cannot open that video format. I have had a similar issue with MacOS, I had to install new decoder so that MacOS could open my *.avi file. Then it worked just fine.

Good luck with that!

2017-03-03 07:47:02 -0600 commented answer CvVideoWriter WriteFrame for iOS not working

Nice Solution. Here is the snippet for python:

import cv2, os cap = cv2.VideoCapture('myvideo.mp4')

if cap.isOpened(): width = cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH) # float height = cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT) # float fname = 'result.m4v' fourcc = cv2.cv.CV_FOURCC(*'XVID') out = cv2.VideoWriter(fname,fourcc, 20.0, (int(width), int(height)))

if os.path.exists(fname): os.remove(fname)