示例#1
0
    def load_annotation_file(self, alov_sub_folder, annotation_file):

        video_path = os.path.join(self.alov_folder, alov_sub_folder,
                                  annotation_file.split('/')[-1].split('.')[0])

        objVideo = video(video_path)
        all_frames = glob.glob(os.path.join(video_path, '*.jpg'))
        objVideo.all_frames = sorted(all_frames)

        with open(annotation_file, 'r') as f:
            data = f.read().rstrip().split('\n')
            for bb in data:
                frame_num, ax, ay, bx, by, cx, cy, dx, dy = bb.split()
                frame_num, ax, ay, bx, by, cx, cy, dx, dy = int(
                    frame_num), float(ax), float(ay), float(bx), float(
                        by), float(cx), float(cy), float(dx), float(dy)

                x1 = min(ax, min(bx, min(cx, dx))) - 1
                y1 = min(ay, min(by, min(cy, dy))) - 1
                x2 = max(ax, max(bx, max(cx, dx))) - 1
                y2 = max(ay, max(by, max(cy, dy))) - 1

                bbox = BoundingBox(x1, y1, x2, y2)
                objFrame = frame(frame_num - 1, bbox)
                objVideo.annotations.append(objFrame)

        video_name = video_path.split('/')[-1]
        self.alov_videos[video_name] = objVideo
        if alov_sub_folder not in self.category.keys():
            self.category[alov_sub_folder] = []

        self.category[alov_sub_folder].append(self.alov_videos[video_name])
示例#2
0
    def load_annotation_file(self, vid_sub_folder, annotation_file):

        video_path = os.path.join(self.vid_folder, vid_sub_folder,
                                  annotation_file)

        objVideo = video(video_path)
        all_frames = glob.glob(os.path.join(video_path, '*.JPEG'))
        logger.info('{:>4} has {:>3} images'.format(annotation_file,
                                                    len(all_frames)))
        objVideo.all_frames = sorted(all_frames)

        annotation_xml = sorted(
            glob.glob(
                os.path.join(self.annotations_folder, vid_sub_folder,
                             annotation_file, '*.xml')))

        for frame_num, xml in enumerate(annotation_xml):
            root = ET.parse(xml).getroot()
            folder = root.find('folder').text
            filename = root.find('filename').text
            size = root.find('size')
            disp_width = int(size.find('width').text)
            disp_height = int(size.find('height').text)

            # trackid 0 only
            for obj in root.findall('object'):
                if obj.find('trackid').text == '0':
                    bbox = obj.find('bndbox')
                    xmin = int(bbox.find('xmin').text)
                    xmax = int(bbox.find('xmax').text)
                    ymin = int(bbox.find('ymin').text)
                    ymax = int(bbox.find('ymax').text)

                    bbox = BoundingBox(xmin, ymin, xmax, ymax)
                    objFrame = frame(frame_num, bbox)
                    objVideo.annotations.append(objFrame)

        video_name = video_path.split('/')[-1]
        self.vid_videos[video_name] = objVideo
        if vid_sub_folder not in self.category.keys():
            self.category[vid_sub_folder] = []

        self.category[vid_sub_folder].append(self.vid_videos[video_name])
示例#3
0
import numpy as np
import cv2
import video

# Number of frames of the video
count = video.frame()

# Haar cascade
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

for i in xrange(0, count - 1):

    img = cv2.imread("frames/frame%d.jpg" % i)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
    for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 0), 2)
        roi_gray = gray[y:y + h, x:x + w]
        roi_color = img[y:y + h, x:x + w]
        # Save in a folder the image of the face (gray and colour)
        cv2.imwrite("fc/f%d.jpg" % i, roi_color)
        cv2.imwrite("fg/f%d.jpg" % i, roi_gray)