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

Unable to see detection results and bounding boxes in python wrapper #1282

Open
jillelajitta opened this issue Jul 26, 2018 · 0 comments
Open

Comments

@jillelajitta
Copy link

Hi Alexy,

I tried running darknet.py with my web camera, I am unable to see detection results and bounding boxes . I added the code from issue #955. Could you please help me resolving this problem. Below is my code.

def capture(thresh=.5, hier_thresh=.5, nms=.45, configPath = "./cfg/yolov3.cfg", weightPath = "yolov3.weights", metaPath= "./data/coco.data", showImage= True, makeImageOnly = False, initOnly= False):
global metaMain, netMain, altNames #pylint: disable=W0603
assert 0 < thresh < 1, "Threshold should be a float between zero and one (non-inclusive)"
if not os.path.exists(configPath):
raise ValueError("Invalid config path "+os.path.abspath(configPath)+"")
if not os.path.exists(weightPath):
raise ValueError("Invalid weight path "+os.path.abspath(weightPath)+"")
if not os.path.exists(metaPath):
raise ValueError("Invalid data file path "+os.path.abspath(metaPath)+"")
if netMain is None:
netMain = load_net_custom(configPath.encode("ascii"), weightPath.encode("ascii"), 0, 1) # batch size = 1
if metaMain is None:
metaMain = load_meta(metaPath.encode("ascii"))
if altNames is None:
# In Python 3, the metafile default access craps out on Windows (but not Linux)
# Read the names file and create a list to feed to detect
try:
with open(metaPath) as metaFH:
metaContents = metaFH.read()
import re
match = re.search("names *= (.)$", metaContents, re.IGNORECASE | re.MULTILINE)
if match:
result = match.group(1)
else:
result = None
try:
if os.path.exists(result):
with open(result) as namesFH:
namesList = namesFH.read().strip().split("\n")
altNames = [x.strip() for x in namesList]
except TypeError:
pass
except Exception:
pass
if initOnly:
print("Initialized detector")
return None

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):
            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)))
    print(res)
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

capture.release()
cv2.destroyAllWindows()

Thanks

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

No branches or pull requests

1 participant