Virtual-Makeup
Virtual-Makeup copied to clipboard
nail.py code. TypeError, IndexError
Hi,
in nail.py I've got this error. TypeError and IndexError.
$ python nail.py
Traceback (most recent call last):
File "nail.py", line 61, in
I resolved this line change. #a, b=round(a), round(b) a = int (round(a)) b = int (round(b))
After that, I also got error message. IndexError.
Traceback (most recent call last):
File "nail.py", line 65, in :
), ellipsis (...
), numpy.newaxis (None
) and integer or boolean arrays are valid indices
I resolved by int value. apply x list to int type.
change to int type
int_x = map(int,x) int_y = map(int,y)
and use int_x lather than x, int_y lather than y. val2 = color.rgb2lab((im[int_x, int_y]/255.).reshape(len(int_x), 1, 3)).reshape(len(int_x), 3)
this line also replaced. x substituted by int_x and y by int_y im[int_x, int_y] = color.lab2rgb(val2.reshape(len(int_x), 1, 3)).reshape(len(int_x), 3)*255
then I can see result image. in Ubuntu 16.10 python 2.7
blush.py is ok. but lipstick.py is also same issue. Maybe this change also could be applied to lipstick.py file.
I share for others. Thank you.
in python 3 map function have to change little bit different way. http://stackoverflow.com/questions/7368789/convert-all-strings-in-a-list-to-int
Hello HyunmokMoon,
I'm trying to make lipstick.py work. I have same error as you had with nail.py. I followed your advice and changed to int type, but still got the error:
Traceback (most recent call last):
File "lipstick.py", line 77, in :
), ellipsis (...
), numpy.newaxis (None
) and integer or boolean arrays are valid indices
Any new advice on how to make it work?? I'm new to python and can't step over this error. Here is my modified code:
x = [] #will contain the x coordinates of points on lips y = [] #will contain the y coordinates of points on lips
int_x = map(int,x) int_y = map(int,y)
def ext(a,b,i): a=int(round(a)) b=int(round(b)) #print(arange(a,b,1)) int_x.extend(arange(a,b,1).tolist()) int_y.extend((ones(b-a)*i).tolist())
for i in range(int(o_u_l[1][0]),int(i_u_l[1][0]+1)): ext(o_u_l0,o_l0+1,i)
for i in range(int(i_u_l[1][0]),int(o_u_l[1][-1]+1)): ext(o_u_l0,i_u_l0+1,i) ext(i_l0,o_l0+1,i)
for i in range(int(i_u_r[1][-1]),int(o_u_r[1][-1]+1)): ext(o_u_r0,o_l0+1,i)
for i in range(int(i_u_r[1][0]),int(i_u_r[1][-1]+1)): ext(o_u_r0,i_u_r0+1,i) ext(i_l0,o_l0+1,i)
val = color.rgb2lab((im[int_x,int_y]/255.).reshape(len(int_x),1,3)).reshape(len(int_x),3) L,A,B = mean(val[:,0]),mean(val[:,1]),mean(val[:,2]) L1,A1,B1 = color.rgb2lab(np.array((r/255.,g/255.,b/255.)).reshape(1,1,3)).reshape(3,) ll,aa,bb = L1-L,A1-A,B1-B val[:,0] += ll val[:,1] += aa val[:,2] += bb #val[:,0] = np.clip(val[:,0], 0, 100) #val[:,1] = np.clip(val[:,1], -127, 128) #val[:,2] = np.clip(val[:,2], -127, 128)
im[int_x,int_y] = color.lab2rgb(val.reshape(len(int_x),1,3)).reshape(len(int_x),3)*255 gca().set_aspect('equal', adjustable='box') imshow(im) show() imsave('output.jpg',im)
Many thanks!!
Problem solved. Was my bad : int_x and int_y moved after x and y took the values:
x = [] y = []
def ext(a,b,i): a=int(round(a)) b=int(round(b)) #print(arange(a,b,1)) int_x.extend(arange(a,b,1).tolist()) int_y.extend((ones(b-a)*i).tolist())
int_x = map(int,x) int_y = map(int,y)
hello @antonov7 i tried your suggested solution but it doesnt work for me
Yes, this is not working for me either. @antonov7 - any other suggestions?