Ask Your Question

Revision history [back]

how to append list's element to an array - python opencv

i have to blue, green and red channels mean values in a separate list, and now i want to append all these values to a single list/ array. my code is like this:

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 = sum(blue) / total
   G = sum(green) / total
   R = sum(red) / total
   B_mean.append(B)
   G_mean.append(G)
   R_mean.append(R)
main_list = [[],[],[]]
main_list[0] = B_mean
main_list[1] = G_mean
main_list[2] = R_mean
print main_list

But the problem is, it is not printing the values, instead its displaying zeros only. So, how do i achieve this?

Thanks!

how to append list's element to an array - python opencv

i have to blue, green and red channels mean values in a separate list, and now i want to append all these values to a single list/ array. my code is like this:

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 = sum(blue) / total
   G = sum(green) / total
   R = sum(red) / total
   B_mean.append(B)
   G_mean.append(G)
   R_mean.append(R)
main_list = [[],[],[]]
main_list[0] = B_mean
main_list[1] = G_mean
main_list[2] = R_mean
print main_list

But the problem is, it is not printing the values, instead its displaying zeros only. So, how do i achieve this?

Thanks!

click to hide/show revision 3
retagged

updated 2014-02-24 04:22:39 -0500

berak gravatar image

how to append list's element to an array - python opencv

i have to blue, green and red channels mean values in a separate list, and now i want to append all these values to a single list/ array. my code is like this:

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 = sum(blue) / total
   G = sum(green) / total
   R = sum(red) / total
   B_mean.append(B)
   G_mean.append(G)
   R_mean.append(R)
main_list = [[],[],[]]
main_list[0] = B_mean
main_list[1] = G_mean
main_list[2] = R_mean
print main_list

But the problem is, it is not printing the values, instead its displaying zeros only. So, how do i achieve this?

Thanks!