Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with opencv clahe.apply()

In the following code Im taking each frame of a video and performing histogram equalization with opencv's CLAHE functions.

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)

However this error is returned at the last line (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
like image 961
Ryan Winstead Avatar asked Mar 13 '18 20:03

Ryan Winstead


1 Answers

convert each frame to grayscale or apply it on each channel

#convert to grayscale
gray_image = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
like image 93
Yousif H Avatar answered Oct 27 '22 11:10

Yousif H