gpt4 book ai didi

python - 使用 OpenCV python 查看原始 10 位 USB 相机

转载 作者:行者123 更新时间:2023-12-02 16:07:17 26 4
gpt4 key购买 nike

我正在尝试查看 Omnivision OV7251 的输出OpenCV 4.2.0 Python 3.5.6 中的相机。相机输出是 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 raw 10-bit OV7251

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

有什么办法可以:
  • 告诉 OpenCV 相机的正确数据格式,以便正确进行转换?
  • 获取原始相机数据以便我可以手动进行转换?
  • 最佳答案

    一种方法是获取原始相机数据,然后使用 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

    关于python - 使用 OpenCV python 查看原始 10 位 USB 相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60113356/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com