在下面的代码中,Im拍摄视频的每一帧,并使用opencv的CLAHE函数执行直方图均衡。

import numpy as np
import matplotlib.pyplot as plt
import cv2
import imutils


#Read video
while True:
    VIDEO = cv2.VideoCapture('cellvid3.avi')
    ok, videoWidget = VIDEO.read();
    image = VIDEO.get(cv2.CAP_PROP_POS_FRAMES);
    #Adaptive Histogram Equalization
    clahe = cv2.createCLAHE(clipLimit=6, tileGridSize= (8,8))
    cl1 = clahe.apply(image)

但是,此错误在最后一行返回(clahe.apply)
    Failed to parse avi: index was not found
OpenCV Error: Assertion failed (_src.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3)) || _src.type() == (((2) & ((1 << 3) - 1)) + (((1)-1) << 3))) in `anonymous-namespace'::CLAHE_Impl::apply, file C:\projects\opencv-python\opencv\modules\imgproc\src\clahe.cpp, line 360
Traceback (most recent call last):
  File "ContoursVid.py", line 23, in <module>
    cl1 = clahe.apply(image)
cv2.error: C:\projects\opencv-python\opencv\modules\imgproc\src\clahe.cpp:360: error: (-215) _src.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3)) || _src.type() == (((2) & ((1 << 3) - 1)) + (((1)-1) << 3)) in function `anonymous-namespace'::CLAHE_Impl::apply

最佳答案

将每个帧转换为灰度或将其应用于每个 channel

#convert to grayscale
gray_image = cv.cvtColor(image, cv.COLOR_BGR2GRAY)

10-08 05:39