簡體   English   中英

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

[英]View a raw10 bit usb camera using OpenCV python

我正在嘗試在 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 位 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM