thearn / webcam-pulse-detector

A python application that detects and highlights the heart-rate of an individual (using only their own webcam) in real-time.
Other
3.14k stars 592 forks source link

The image is flipped & frame rate #44

Open chungbrain opened 6 years ago

chungbrain commented 6 years ago

Hi all,

To begin with, thanks for sharing this code. I have a quick question about flipped image whenever I ran this code.

Is there any particular reason for a flipped image on pop up window? otherwise is it just for me?

In order to fix this problem, I add just one line on the "def get_frame of device.py" as below.


class Camera(object):

def __init__(self, camera = 0):
    self.cam = cv2.VideoCapture(camera)
    self.valid = False
    try:
        resp = self.cam.read()
        #self.shape = resp[1].shape
        self.shape = cv2.flip(resp[1].shape, 1)
        self.valid = True
    except:
        self.shape = None

def get_frame(self):
    if self.valid:
        _,frame = self.cam.read()
        frame = cv2.flip(frame, 1)
    else:
        frame = np.ones((480,640,3), dtype=np.uint8)
        col = (0,256,256)
        cv2.putText(frame, "(Error: Camera not accessible)",
                   (65,220), cv2.FONT_HERSHEY_PLAIN, 2, col)
    return frame

The reason I ask you is I would like to extract time series heart rate as a single csv file without sampling distortion. Extracting time series signal can be utilized to analyze my personal research.

Please let me know if you guys have ideas and comments.

Thanks.