AlexeyAB / darknet

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

python wrapper resize to network.size #3261

Open marfis89 opened 5 years ago

marfis89 commented 5 years ago

Hi Alexy,

I have a cropped video (240x1805) If I use the video directly with the darknet detector demo everything works perfect. But when I use the darknet_video.py wrapper the video gets 1: 1 ( in network width and height)

frame_resized = cv2.resize(frame_rgb, (darknet.network_width(netMain), darknet.network_height(netMain)), interpolation=cv2.INTER_LINEAR)

Why is the resize necessary?

Thank you for the great work!

marfis89 commented 5 years ago

This works perfectly: `

ret, frame_read = cap.read()
frame_height, frame_width, _ = frame_read.shape

out = cv2.VideoWriter("output.avi", cv2.VideoWriter_fourcc(*"MJPG"), 10.0,(frame_width, frame_height))
print("Starting the YOLO loop...")

# Create an image we reuse for each detect    
darknet_image = darknet.make_image(frame_width,frame_height,3)

while True:

    prev_time = time.time()
    ret, frame_read = cap.read()
    frame_height, frame_width, _ = frame_read.shape        
    frame_rgb = cv2.cvtColor(frame_read, cv2.COLOR_BGR2RGB)
    frame_resized = cv2.resize(frame_rgb,(frame_width,frame_height), interpolation=cv2.INTER_LINEAR)

    darknet.copy_image_from_bytes(darknet_image,frame_resized.tobytes())

    detections = darknet.detect_image(netMain, metaMain, darknet_image, thresh=0.10)
    image = cvDrawBoxes(detections, frame_resized)
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    print(1/(time.time()-prev_time))
    out.write(image)

    cv2.imshow('Python Demo', image)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

`

aniketvartak commented 5 years ago

yes, this works.thanks

zhijiejia commented 4 years ago

ok i am happy !!!!

mazatov commented 4 years ago

@marfis89, did you figure out what is the difference between resizing the image to the model size? Both seem to give similar, yet not identical results.

As in,

darknet_image = darknet.make_image(darknet.network_width(netMain),
                                    darknet.network_height(netMain),3)

instead of

# Create an image we reuse for each detect    
darknet_image = darknet.make_image(frame_width,frame_height,3)