iagcwdのプログラムをそのまま使用しているのですが、
error
1OpenCV(3.4.1) Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/color.cpp, line 11180 2Traceback (most recent call last): 3 File "IAGCWD.py", line 89, in <module> 4 main() 5 File "IAGCWD.py", line 62, in main 6 YCrCb = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb) 7cv2.error: OpenCV(3.4.1) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/color.cpp:11180: error: (-215) scn == 3 || scn == 4 in function cvtColor
となっています。
調べたところ、【エラー解決】error: (-215) scn == 3 || scn == 4 in function cvtColorというサイトでパス指定が間違っているとなっていました。
どこが間違えているのか教えていただけませんか?
または、画像の指定をどの様に変更すればいいのか教えてください。
python
1import cv2 2import glob 3import argparse 4import numpy as np 5from matplotlib import pyplot as plt 6from scipy.linalg import fractional_matrix_power 7 8def image_agcwd(img, a=0.25, truncated_cdf=False): 9 h,w = img.shape[:2] 10 hist,bins = np.histogram(img.flatten(),256,[0,256]) 11 cdf = hist.cumsum() 12 cdf_normalized = cdf / cdf.max() 13 prob_normalized = hist / hist.sum() 14 15 unique_intensity = np.unique(img) 16 intensity_max = unique_intensity.max() 17 intensity_min = unique_intensity.min() 18 prob_min = prob_normalized.min() 19 prob_max = prob_normalized.max() 20 21 pn_temp = (prob_normalized - prob_min) / (prob_max - prob_min) 22 pn_temp[pn_temp>0] = prob_max * (pn_temp[pn_temp>0]**a) 23 pn_temp[pn_temp<0] = prob_max * (-((-pn_temp[pn_temp<0])**a)) 24 prob_normalized_wd = pn_temp / pn_temp.sum() # normalize to [0,1] 25 cdf_prob_normalized_wd = prob_normalized_wd.cumsum() 26 27 if truncated_cdf: 28 inverse_cdf = np.maximum(0.5,1 - cdf_prob_normalized_wd) 29 else: 30 inverse_cdf = 1 - cdf_prob_normalized_wd 31 32 img_new = img.copy() 33 for i in unique_intensity: 34 img_new[img==i] = np.round(255 * (i / 255)**inverse_cdf[i]) 35 36 return img_new 37 38def process_bright(img): 39 img_negative = 255 - img 40 agcwd = image_agcwd(img_negative, a=0.25, truncated_cdf=False) 41 reversed = 255 - agcwd 42 return reversed 43 44def process_dimmed(img): 45 agcwd = image_agcwd(img, a=0.75, truncated_cdf=True) 46 return agcwd 47 48def main(): 49 parser = argparse.ArgumentParser(description='IAGCWD') 50 parser.add_argument('--input', dest='input_dir', default='./input/', type=str, \ 51 help='Input directory for image(s)') 52 parser.add_argument('--output', dest='output_dir', default='./output/', type=str, \ 53 help='Output directory for image(s)') 54 args = parser.parse_args() 55 56 img_paths = glob.glob(args.input_dir+'*') 57 for path in img_paths: 58 img = cv2.imread(path, 1) 59 name = path.split('\')[-1].split('.')[0] 60 61 # Extract intensity component of the image 62 YCrCb = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb) 63 Y = YCrCb[:,:,0] 64 # Determine whether image is bright or dimmed 65 threshold = 0.3 66 exp_in = 112 # Expected global average intensity 67 M,N = img.shape[:2] 68 mean_in = np.sum(Y/(M*N)) 69 t = (mean_in - exp_in)/ exp_in 70 71 # Process image for gamma correction 72 img_output = None 73 if t < -threshold: # Dimmed Image 74 print (name + ": Dimmed") 75 result = process_dimmed(Y) 76 YCrCb[:,:,0] = result 77 img_output = cv2.cvtColor(YCrCb,cv2.COLOR_YCrCb2BGR) 78 elif t > threshold: 79 print (name + ": Bright Image") # Bright Image 80 result = process_bright(Y) 81 YCrCb[:,:,0] = result 82 img_output = cv2.cvtColor(YCrCb,cv2.COLOR_YCrCb2BGR) 83 else: 84 img_output = img 85 86 cv2.imwrite(args.output_dir+name+'.jpg', img_output) 87 88if __name__ == '__main__': 89 main()
自分には間違っている様に思えないので、助けてください。
お願い致します。
私の環境はMacOSです。
$ pip list
Package Version
certifi 2020.6.20
cycler 0.11.0
kiwisolver 1.3.1
matplotlib 3.3.4
numpy 1.19.5
opencv-python 3.4.1.15
Pillow 8.4.0
pip 21.2.2
pyparsing 3.0.6
python-dateutil 2.8.2
scipy 1.5.4
setuptools 58.0.4
six 1.16.0
wheel 0.37.0
あなたの回答
tips
プレビュー