1 | initial version |
here's the culprit:
B = sum(blue) / total
all values are 0 due to integer division. you'll have to change the type to float to make it work:
import cv2
import numpy as np
import os,glob
resizelist = list()
B_mean = list()
G_mean = list()
R_mean = list()
path = '.'
for infile in glob.glob(os.path.join(path,'*.jpg')):
imge = cv2.imread(infile)
arr1 = np.array(imge)
re_img = cv2.resize(imge,(200,200))
resizelist.append(re_img)
blue, green, red = cv2.split(re_img)
total = re_img.size
B = np.float32(sum(blue)) / total
G = np.float32(sum(green)) / total
R = np.float32(sum(red)) / total
B_mean.append(B)
G_mean.append(G)
R_mean.append(R)
main_list = [B_mean,G_mean,R_mean]
print main_list
2 | No.2 Revision |
here's the culprit:
B = sum(blue) / total
all values are 0 due to integer division. you'll have to change the type to float to make it work:
import cv2
import numpy as np
import os,glob
resizelist = list()
B_mean = list()
G_mean = list()
R_mean = list()
path = '.'
'C:/Users/HP/Desktop/dataset1'
for infile in glob.glob(os.path.join(path,'*.jpg')):
imge = cv2.imread(infile)
arr1 = np.array(imge)
re_img = cv2.resize(imge,(200,200))
resizelist.append(re_img)
blue, green, red = cv2.split(re_img)
total = re_img.size
B = np.float32(sum(blue)) / total
G = np.float32(sum(green)) / total
R = np.float32(sum(red)) / total
B_mean.append(B)
G_mean.append(G)
R_mean.append(R)
main_list = [B_mean,G_mean,R_mean]
print main_list