0

First my Setup: Windows 10, Asus Notebook, Logitech C920 HD Pro Webcam, Opencv-Python 3.4.4.19

When I manually take a photo with the webcam using the Windows 10 Camera App, it is sharp. But if I program a code in Python and use OpenCV the taken photo is blurred (unsharp). When I press the space bar, a photo is taken.

I already tried to play with the contrast, brightness and FPS. Unfortunately this didn't lead to any result.

import cv2
import os
cam = cv2.VideoCapture(1)
cv2.namedWindow("test")
cam.set(3, 1920)
cam.set(4, 1080)
img_counter = 0
myfile="XXX"
if os.path.isfile(myfile):
    os.remove(myfile)
else:    
    print("Error: %s file not found" % myfile)
while True:
    ret, frame = cam.read()
    cv2.imshow("test", frame)
    if not ret:
        break
k = cv2.waitKey(1)
if k%256 == 27:
    print("Escape hit, closing...")
    break
elif k%256 == 32:
    img_name = "Bild{}.png".format(img_counter)
    cv2.imwrite(img_name, frame)
    print("{} written!".format(img_name))
    img_counter += 1
cam.release()
cv2.destroyAllWindows()

Are there settings for OpenCv to get the image sharper? In the final stage I have 3 cameras which automatically take a photo one after the other.

Unsharp Image (OpenCV)
Sharp Image (Windows 10 Kamera App)
Image cv2.imshow

Veysel Olgun
  • 552
  • 1
  • 3
  • 15
David
  • 1
  • 1

2 Answers2

0

Typical camera pipelines have a sharpening filter applied to remove the effect of blurring caused by the scene being out of focus, or poor optics. My guess is that OpenCV is capturing the image closer to "raw" without adding the sharpening filter. You should be able to add a sharpening filter yourself. You can tell when a sharpening filter is applied as there will be a "ringing" artifact around high contrast edges.

0

This is very likely due to bandwidth limits imposed by the USB controller.

If you look closely, the image doesn't actually have 1920x1080 resolution. It appears upscaled.

You asked for Full HD at whatever default frame rate. This is impossible to move uncompressed over USB 2.0 High Speed.

That is why the camera picks some mode that fits within the bandwidth limits. This is often a low resolution mode, or sometimes a low framerate mode.

That is what you see here.

You need to tell OpenCV, besides the resolution, to tell the camera to compress the video.

MJPG is commonly available.

Try both of these. The order of the set calls matters:

cam.set(cv.CAP_PROP_FOURCC, cv.VideoWriter_fourcc(*"MJPG"))
cam.set(cv.CAP_PROP_FRAME_WIDTH, 1920)
cam.set(cv.CAP_PROP_FRAME_HEIGHT, 1080)

# OR

cam.set(cv.CAP_PROP_FRAME_WIDTH, 1920)
cam.set(cv.CAP_PROP_FRAME_HEIGHT, 1080)
cam.set(cv.CAP_PROP_FOURCC, cv.VideoWriter_fourcc(*"MJPG"))
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36