l1npengtul / nokhwa

Cross Platform Rust Library for Powerful Webcam/Camera Capture
Apache License 2.0
521 stars 132 forks source link

Fix decoding image on yuyv #105

Closed hanguk0726 closed 1 year ago

hanguk0726 commented 1 year ago

Hello!

the 'decode_image' function works fine in MJPEG(Logitech C922) but not in YUYV when I tested on Thinkpad-E15 Embedded Webcam (YUYV). It's much slower and the color is ruined. I'm not sure if these snippet is best way, but it worked well when I tried. So I want to get your review.

format :1280x720@1FPS, YUYV Format camera info :Name: Integrated Camera, Description: MediaFoundation Camera Device, Extra: \?\usb#vid_04f2&pid_b604&mi_00#6&31e07f50&0&0000#{e5323777-f976-4f5b-9b55-b94699c46e44}\global, Index: 0 laptop: Thinkpad E15

YUYV original (Thinkpad-E15 Embedded) Time elapsed in decode_function() is: 616.1851ms Time elapsed in decode_function() is: 550.1826ms Time elapsed in decode_function() is: 528.2332ms Time elapsed in decode_function() is: 515.3112ms Time elapsed in decode_function() is: 519.2568ms Time elapsed in decode_function() is: 533.8334ms

YUYV changed (Thinkpad-E15 Embedded) Time elapsed in decode_function() is: 63.4131ms Time elapsed in decode_function() is: 63.8566ms Time elapsed in decode_function() is: 72.9646ms Time elapsed in decode_function() is: 60.6028ms Time elapsed in decode_function() is: 56.9003ms Time elapsed in decode_function() is: 61.4874ms

MJPEG (Thinkpad-E15 Logitech C922) Time elapsed in decode_function() is: 35.1922ms Time elapsed in decode_function() is: 34.2452ms Time elapsed in decode_function() is: 34.3782ms Time elapsed in decode_function() is: 37.3762ms Time elapsed in decode_function() is: 62.1309ms Time elapsed in decode_function() is: 42.7138ms

the ruined image

yuyv

l1npengtul commented 1 year ago

Looks good to me, can you post the decoding result of this one?

hanguk0726 commented 1 year ago

here is the decoded image changed_image

and I made GIFs for comparison. changed

original

l1npengtul commented 1 year ago

Wow, this looks excellent! Thank you! I will merge this later when I have time.