1

I want to acquire images from a scientific camera as 16bit grey scale. The default with OpenCV is 8 bit grey scale. I can't figure out from the documentation how to change the bit depth on acquisition. (The camera is capable and I can configure and acquire images with other programs in 16 bit grey).

import cv2

cap = cv2.VideoCapture(1)

while True:
    ret, img = cap.read()
    print img.dtype
    cv2.imshow("input", img)

    key = cv2.waitKey(10)
    if key == 27:
        break


cv2.destroyAllWindows() 
cv2.VideoCapture(1).release()

Can anyone familiar with setting camera settings in opencv lend a hand? Thank you!

S. Stromberg
  • 69
  • 2
  • 9
  • setting camera settings with opencv is done using the `VideoCapture.set` method. are you certain that opencv supports changing camera settings with your particular camera? http://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-set – derricw Nov 13 '15 at 21:55
  • Yes. I've used `set()` to set the exposure time. Looks like there are a number of candidates on that list you linked to that might control bit-depth. Do you know which one and how to use it? – S. Stromberg Nov 13 '15 at 22:07
  • Setting the codec to Y16 like so `cap.set(cv2.cv.CV_CAP_PROP_FOURCC, cv.CV_FOURCC("Y", "1", "6", " "))` changes nothing in the dtype returned. – S. Stromberg Nov 13 '15 at 22:38
  • Try setting the property CV_CAP_PROP_FORMAT to CV_16U – Miki Nov 13 '15 at 22:47
  • Thanks. Tried your suggestion with `cap.set(cv2.cv.CV_CAP_PROP_FORMAT, cv2.cv.CV_16U)` and it returned `False`. Is there a list of all the other format options? – S. Stromberg Nov 13 '15 at 22:54
  • What does `cap.get(cv2.cv.CV_CAP_PROP_FORMAT)` return? Also, what model is the camera? – derricw Nov 13 '15 at 23:12
  • It returns -1.0, which seems weird to me because if I give -1.0 as a parameter to `set` I still get False. – S. Stromberg Nov 13 '15 at 23:21
  • The camera is an imaging source USB camera. (DMK 24UJ003) – S. Stromberg Nov 13 '15 at 23:21
  • What's the OS and version of OpenCV? (BTW, the camera looks nice.) – Ulrich Stern Feb 23 '16 at 22:27
  • It's Windows 7 and must have been OpenCV 3.0.0. Since I posted the question I've been using other means to control the camera, and with the manufacturer's driver I have to issue a command to remove_overlay before I can capture images with 16 bit depth. I don't know if there is something analogous in OpenCV. – S. Stromberg Feb 24 '16 at 23:43
  • I took a quick look at the OpenCV 3.0.0 code that I think is being used on Windows, and setting of `CV_CAP_PROP_FOURCC` seems implemented (see [here](https://github.com/Itseez/opencv/blob/3.0.0/modules/videoio/src/cap_dshow.cpp#L3215)). Have you checked the supported video formats of your camera? (If you hook it up to a Linux box, `v4l2-ctl -d 0 --list-formats-ext` may list them.) – Ulrich Stern Feb 25 '16 at 06:31
  • might be related to this http://stackoverflow.com/questions/21555572/can-i-set-the-color-depth-while-capturing-the-webcam-image-using-opencv – shawndfernandes Feb 05 '17 at 00:33

0 Answers0