Beispiel #1
0
import cv2
from util import draw_detections, get_svm_vector
import os


if __name__ == "__main__":
    detect_path = "./test_performance/"

    win_size = (40, 40)
    block_size = (10, 10)
    block_stride = (5, 5)
    cell_size = (5, 5)
    nbins = 9
    hog = cv2.HOGDescriptor(win_size, block_size, block_stride, cell_size, nbins)

    vect = get_svm_vector("data_pos_3496_neg_11777.xml")
    hog.setSVMDetector(vect)
    img_name = "03.MOV-3.jpg"
    # for img_name in os.listdir(detect_path):
    img = cv2.imread(detect_path + img_name)

    if img_name.find("avi") >= 0:
        img = cv2.resize(img, (img.shape[1] / 2, img.shape[0] / 2))

    found, w = hog.detectMultiScale(img, winStride=(8, 8), scale=1.05)
    draw_detections(img, found)
    cv2.imshow("test", img)
    if cv2.waitKey(0) & 0xFF == 27:
        cv2.destroyAllWindows()
Beispiel #2
0
    def detect(self):
        while self.vdo.grab():
            start = time.time()
            _, im = self.vdo.retrieve()
            # im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
            print(
                '----------------------------------------------DEMO started-----------------------------------------------'
            )
            bbox_xcycwh, cls_conf, cls_ids, cls_masks, bbox_xyxy_detectron2 = self.detectron2.detect(
                im)
            #print('bbox_xcycwh, cls_conf, cls_ids, cls_masks', bbox_xcycwh, cls_conf, cls_ids, cls_masks)

            #if bbox_xcycwh is not None:
            current_counter = []
            if len(bbox_xcycwh):
                mask = cls_ids == 0  # select class person
                #print('mask>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>', mask)

                #print('bbox_xcycwh', bbox_xcycwh)
                bbox_xcycwh = bbox_xcycwh[mask]

                #print('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^cls_conf', cls_conf)
                cls_conf = cls_conf[mask]
                #print('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^cls_masks[mask]', cls_conf[mask])
                binary_masks = cls_masks[mask]
                #binary_masks = cls_masks

                #draw detections after NMS, white box

                outputs, detections = self.deepsort.update(
                    bbox_xcycwh, cls_conf, im)
                im = draw_detections(detections, im)
                print(
                    '++++++++++++++++++++++++++++++++++++++ outputs of deepsort.update',
                    outputs)
                if len(outputs):
                    bbox_xyxy = outputs[:, :4]
                    print(
                        "+++++++++++++++++++++++++++++++++++++bbox_xyxy, bbox_xyxy_detectron2",
                        bbox_xyxy, bbox_xyxy_detectron2)
                    identities = current_counter = outputs[:, -1]
                    #print("+++++++++++++++++++++++++++++++++++++identities", identities)
                    ordered_identities = []
                    for identity in identities:
                        if not self.total_counter[identity]:
                            self.total_counter[identity] = max(
                                self.total_counter) + 1
                        ordered_identities.append(self.total_counter[identity])
                    im = draw_bboxes(im, bbox_xyxy, ordered_identities,
                                     binary_masks)
                    #nums = "len(bbox_xyxy): {}, len(identities): {}, len(binary_masks): {}".format(len(bbox_xyxy), len(identities), len(binary_masks))
                    #im = cv2.putText(im, nums, (150, 150), cv2.FONT_HERSHEY_PLAIN, 2, [255,255,255], 2)

            end = time.time()
            time_fps = "time: {}s, fps: {}".format(round(end - start, 2),
                                                   round(1 / (end - start), 2))
            im = cv2.putText(
                im, "Total Hand Counter: " + str(max(self.total_counter)),
                (int(20), int(120)), 0, 5e-3 * 200, (0, 255, 0), 2)
            im = cv2.putText(
                im, "Current Hand Counter: " + str(len(current_counter)),
                (int(20), int(80)), 0, 5e-3 * 200, (0, 255, 0), 2)
            im = cv2.putText(im, time_fps, (int(20), int(40)), 0, 5e-3 * 200,
                             (0, 255, 0), 3)
            if self.args.display:
                cv2.imshow("test", im)
                cv2.waitKey(1)

            if self.args.save_path:
                self.output.write(im)
Beispiel #3
0
path = '/home/xsyin/video/'

if __name__ == '__main__':

    win_size = (40, 40)
    block_size = (10, 10)
    block_stride = (5, 5)
    cell_size = (5, 5)
    nbins = 9
    hog = cv2.HOGDescriptor(win_size, block_size, block_stride, cell_size, nbins)

    video_path = path + '02.mp4'
    vector = get_svm_vector('svm_data.xml')
    hog.setSVMDetector(vector)
    cap = cv2.VideoCapture(video_path)
    i = 0
    while True:
        _, frame = cap.read()
        if i%100 == 0:
            found, w = hog.detectMultiScale(frame, winStride=(8, 8), scale=1.02)
        draw_detections(frame, found)
        cv2.imshow('video', frame)
        i += 1
        ch = 0xFF & cv2.waitKey(1)
        if ch == 27:
            break

cap.release()
cv2.destroyAllWindows()