jeudi 8 mai 2014

python - égalisation d'histogramme couleur sur la vidéo capturée - Stack Overflow


I have this code to perform histogram equalization on the video captured from a cam after converting to grayscale using OpenCV 2.3.1 and Python in Debian Linux.


cap=cv2.VideoCapture(0)

while(True):
ret, frame=cap.read()
cv2.imshow('frame', frame)
if (cap.isOpened()):
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv2.equalizeHist(gray)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
cv2.destroyAllWindows()

What I intend to do is instead of converting to grayscale I want to convert it to HSI color space and then perform equalization on only the intensity parameter and finally write the video back to a file. Any help would be appreciated.




I'm not sure that OpenCV provides a function for RGB to HSI conversion (you might use HSV or HSL). After the conversion of the image, use the "split" function. I haven't used Python with OpenCV, but in C++ the "split" function returns a vector of Mat images that represent all the channels (H, S and V for example). After this, perform the required operations on the channel that you wish and use the "merge" function to combine the results (you provide the function an array of images and it returns the result image).


I hope it helps you!



I have this code to perform histogram equalization on the video captured from a cam after converting to grayscale using OpenCV 2.3.1 and Python in Debian Linux.


cap=cv2.VideoCapture(0)

while(True):
ret, frame=cap.read()
cv2.imshow('frame', frame)
if (cap.isOpened()):
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv2.equalizeHist(gray)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
cv2.destroyAllWindows()

What I intend to do is instead of converting to grayscale I want to convert it to HSI color space and then perform equalization on only the intensity parameter and finally write the video back to a file. Any help would be appreciated.



I'm not sure that OpenCV provides a function for RGB to HSI conversion (you might use HSV or HSL). After the conversion of the image, use the "split" function. I haven't used Python with OpenCV, but in C++ the "split" function returns a vector of Mat images that represent all the channels (H, S and V for example). After this, perform the required operations on the channel that you wish and use the "merge" function to combine the results (you provide the function an array of images and it returns the result image).


I hope it helps you!


0 commentaires:

Enregistrer un commentaire