How to restore web-cam to default settings after ruining them with OpenCV settings?

Viewed 1675

I need video from web-cam. On Anaconda with python-3.6 and OpenCV-3 it worked fine. I tried then the same code in Idle with python-3.6 and OpenCV-4.1.0 and it did not worked in anaconda. I had two black upper and lower edges, and I could only see the middle of the image. I tried to modify some OpenCV settings and it only got worse, now I barely see anything on the image, only if I put strong light. The two edges did not disappeared.

import cv2

capture = cv2.VideoCapture(0)
capture.set(cv2.CAP_PROP_SETTINGS, 0)

while(True):

    ret, frame = capture.read()
    cv2.imshow('video', frame)
    if cv2.waitKey(1) == 27:
        break

capture.release()
cv2.destroyAllWindows()

The line capture.set(cv2.CAP_PROP_SETTINGS, 0) opens a small settings dialog, but there are many other, like this:

  1. CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds.
  2. CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
  3. CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file
  4. CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
  5. CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
  6. CV_CAP_PROP_FPS Frame rate.
  7. CV_CAP_PROP_FOURCC 4-character code of codec.
  8. CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.
  9. CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() .
  10. CV_CAP_PROP_MODE Backend-specific value indicating the current capture mode.
  11. CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for cameras).
  12. CV_CAP_PROP_CONTRAST Contrast of the image (only for cameras).
  13. CV_CAP_PROP_SATURATION Saturation of the image (only for cameras).
  14. CV_CAP_PROP_HUE Hue of the image (only for cameras).
  15. CV_CAP_PROP_GAIN Gain of the image (only for cameras).
  16. CV_CAP_PROP_EXPOSURE Exposure (only for cameras).
  17. CV_CAP_PROP_CONVERT_RGB Boolean flags indicating whether images should be converted to RGB.
  18. CV_CAP_PROP_WHITE_BALANCE Currently unsupported
  19. CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)

I tried to install some camera drivers from asus, but couldn't find any for my model: FX504GE . Is there any combination of this settings or smth to restore my web-cam? I really need it rn...

2 Answers

The simple way is to use v4l2-ctrl to read in all parameters when you launch the camera. record down the initial value. After you have done in opencv. use v4l2-ctrl to set.

eg. size

v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=YUYV

there are other like auto zoom auto expsoure and lot of things read all and set all

Related