【问题标题】:View a raw10 bit usb camera using OpenCV python使用 OpenCV python 查看 raw10 位 USB 相机
【发布时间】:2020-05-23 14:02:03
【问题描述】:

我正在尝试在 OpenCV 4.2.0 Python 3.5.6 中查看 Omnivision OV7251 相机的输出。相机输出是 10 位原始灰度数据,我相信它在 16 位字中是右对齐的。

当我使用这个 OpenCV 代码时:

import cv2

cam2 = cv2.VideoCapture(0)
cam2.set(3, 640)            # horizontal pixels
cam2.set(4, 480)            # vertical pixels

while True:
    b, frame = cam2.read()

    if b:
        cv2.imshow("Video", frame)

        k = cv2.waitKey(5)

        if k & 0xFF == 27:
            cam2.release()
            cv2.destroyAllWindows()
            break

这是我得到的图像:

可能发生的事情是 OpenCV 使用错误的过程将 10 位原始转换为 RGB,认为它是某种 YUV 或其他东西。

有什么办法可以:

  • 告诉 OpenCV 相机的正确数据格式,以便正确进行转换?
  • 获取原始相机数据以便我可以手动进行转换?

【问题讨论】:

  • 视频或照片?文档明确说“RAW”? (不是“LOG”之类的东西)?对于照片而言,RAW 是一种未经校正的 RGB,但您会得到两倍的 G,并且滤镜的色度(以及每个滤镜的强度)与 sRGB 不同。视频通常具有未校正(或线性)空间,通常为 10 位,但它并不是真正的原始空间(所以 YCC)。您应该尝试使用图案(黑色、白色和少量灰色的带 + 完全饱和颜色的带),以获取有关颜色编码的更多信息。

标签: python opencv camera computer-vision color-space


【解决方案1】:

一种方法是获取原始相机数据,然后使用 numpy 进行纠正:

import cv2
import numpy as np

cam2 = cv2.VideoCapture(0)
cam2.set(3, 640)            # horizontal pixels
cam2.set(4, 480)            # vertical pixels

cam2.set(cv2.CAP_PROP_CONVERT_RGB, False);          # Request raw camera data

while True:
    b, frame = cam2.read()

    if b:
        frame_16 = frame.view(dtype=np.int16)       # reinterpret data as 16-bit pixels
        frame_sh = np.right_shift(frame_16, 2)      # Shift away the bottom 2 bits
        frame_8  = frame_sh.astype(np.uint8)        # Keep the top 8 bits       
        img      = frame_8.reshape(480, 640)        # Arrange them into a rectangle

        cv2.imshow("Video", img)

        k = cv2.waitKey(5)

        if k & 0xFF == 27:
            cam2.release()
            cv2.destroyAllWindows()
            break

【讨论】:

    猜你喜欢
    • 2019-06-16
    • 2021-02-14
    • 2012-09-05
    • 2013-01-04
    • 1970-01-01
    • 1970-01-01
    • 2017-04-14
    • 1970-01-01
    • 2017-07-17
    相关资源
    最近更新 更多