AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.65k stars 7.96k forks source link

cannot detect object from web camera #994

Open xuesongle opened 6 years ago

xuesongle commented 6 years ago

@AlexeyAB I use some of your sample code from https://github.com/AlexeyAB/darknet/issues/955 and copy that function in darknet.py, but it seems that it cannot detect any objects.

    def capture(thresh=.5, hier_thresh=.5, nms=.45, configPath = "./cfg/yolov3.cfg", weightPath = "yolov3.weights", metaPath= "./cfg/coco.data", showImage= True, makeImageOnly = False, initOnly= False):
    global metaMain, netMain, altNames #pylint: disable=W0603
    netMain = load_net_custom(configPath.encode("ascii"), weightPath.encode("ascii"), 0, 1)  # batch size = 1
    metaMain = load_meta(metaPath.encode("ascii"))

    num = c_int(0)
    pnum = pointer(num)
    num = pnum[0]

    capture = cv2.VideoCapture(0)
    print(capture.get(cv2.CAP_PROP_FPS))

    capture.set(cv2.CAP_PROP_FRAME_WIDTH, 1024)
    capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 768)

    while True:
        ret, frame = capture.read()
        im, arr = array_to_image(frame)
        predict_image(netMain, im)
        dets = get_network_boxes(netMain, im.w, im.h, thresh, hier_thresh, None, 0, pnum, 1)
        if nms:
            do_nms_sort(dets, num, metaMain.classes, nms)
        res = []
        for j in range(num):
            for i in range(metaMain.classes):
                print("i: %d", i)
                print (dets[j].prob[i])
                if dets[j].prob[i] > 0:
                    b = dets[j].bbox
                    nameTag = metaMain.names[i]
                    res.append((nameTag, dets[j].prob[i], (b.x, b.y, b.w, b.h)))
                    x1, y1 = int(b.x - b.w/2), int(b.y - b.h/2)
                    x2, y2 = int(b.x + b.w/2), int(b.y + b.h/2)
                    cv2.rectangle(frame, (x1, y1), (x2, y2), (0,255,0), 2)
                    print("detected: ")
        print(res)
        cv2.imshow('frame', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    capture.release()
    cv2.destroyAllWindows()
ZhangBihui0311 commented 6 years ago

Same problem.... I am using Ubuntu16.04 with Anaconda3-5.1.0 and opencv-3.2.0 Please Help~~~ @AlexeyAB

I just found that after num = c_int(0) pnum = pointer(num) num = pnum[0] the initial num is 0 in the while loop pnum always changes but num dose not change anymore