histogram equalization for colored image give error using python opencv -


error : assertion failed (0 < cn && cn <= cv_cn_max) in merge

in merge function

cv2.merge(channels,img2) 

if arguments replaced shown:

cv2.merge(img2,channels) 

it not give error, histograms same before , after equalization. can in piece of code.

code:

import cv2,cv import cv2.cv cv import numpy np matplotlib import pyplot plt  capture = cv.capturefromcam(0) img = cv.queryframe(capture) img_size = cv.getsize(img)  width,height = img_size size = width,height,3 channels = np.zeros(size , np.uint8)    while (1): img = cv.queryframe(capture) img = np.asarray(img[:,:])  cv2.imshow("original",img) hist = cv2.calchist([img],[2],none,[256],[0,256])  #convert img ycr_cb img2 = cv2.cvtcolor(img,cv2.color_bgr2ycr_cb)  #split image y, cr, cb cv2.split(img2,channels)  #histogram equalization y-matrix cv2.equalizehist(channels[0],channels[0])  #merge matrix reconstruct our colored image cv2.merge(channels,img2)  #convert output image rgb rgb = cv2.cvtcolor(img2,cv2.color_ycr_cb2bgr) hist2 = cv2.calchist([rgb],[2],none,[256],[0,256]) plt.plot(hist) plt.plot(hist2) plt.show() 

instead of using split , merge, take advantage of numpy slicing.

img2[:, :, 0] = cv2.equalizehist(img2[:, :, 0])  # or run small loop on each channel 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -