如何在 Python 中创建一个实时进程,从摄像头获取实时反馈并绘制其 RGB 光谱?

问题描述 投票:0回答:1

我正在开发一个简单的程序,该程序从 LuCam 模型获取数据,然后在对其执行 fft 后绘制结果光谱。然后,我想将这些值划分为各自的 RGB 值,并仅绘制其中一个值,例如 R 值。我的麻烦是,我不知道如何准确地将传入的实时数据划分为单独的 RGB 值,然后选择何时对它们进行傅立叶变换。

我认为 cv2 库最适合这种情况,因此我导入了它并希望从我的相机获取实时反馈。所以我这样做了:

import cv2 as cv

# Initialize the camera
cam = cv.VideoCapture(0)

# Start an infinite loop for real-time image processing
while True:
    # Read a frame from the camera
    status, photo = cam.read()

    # Perform image manipulation: cropping and copying
    photo[0:200, 0:150] = photo[100:300, 150:300]

    # Check for the 'Enter' key press to exit the loop
    if cv.waitKey(10) == 13:
        break

# Release the camera and close all windows
cv.destroyAllWindows()
cam.release()

从这里开始,我真的不知道该去哪里。我应该将 feed 转换为 RGB,然后忽略绿色和蓝色值吗?我该如何去做呢?然后我要对其进行 fft 并在之后或在 while 循环内绘制它吗?

python computer-vision fft real-time rgb
1个回答
0
投票

要将照片分成三个通道,请使用:

b, g, r = cv2.split(photo)

您现在拥有作为单独的二维阵列的三个通道。要获取图像的频谱,需要使用 fft2:

imFFT = np.fft.fft2(Whateveryouchoose) # take FFT
imFFTShifted = np.fft.fftshift(imFFT) # shift to centre
magSpectrum = np.abs(imFFTShifted) # this is how you calculate the magSpectrum
phaseSpectrum = np.angle(imFFTShifted) # this is the phaseSpectrum
fig, ax = plt.subplots(nrows = 1, ncols = 3)
ax[0].imshow(im)
ax[1].imshow(magSpectrum, norm = LogNorm())
ax[2].imshow(phaseSpectrum, norm = LogNorm())
© www.soinside.com 2019 - 2024. All rights reserved.