Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot detect object from web camera #994

Open
xuesongle opened this issue Jun 7, 2018 · 1 comment
Open

cannot detect object from web camera #994

xuesongle opened this issue Jun 7, 2018 · 1 comment
Labels

Comments

@xuesongle
Copy link

xuesongle commented Jun 7, 2018

@AlexeyAB I use some of your sample code from #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
Copy link

ZhangBihui0311 commented Jul 3, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants