Sign in
Log inSign up
Nisarg Kapkar

188 likes

·

11.1K reads

10 comments

vaibhav kumar
vaibhav kumar
Jan 1, 2021

Good One!

2
·
·3 replies
Nisarg Kapkar
Nisarg Kapkar
Author
·Jan 1, 2021

Thank You! A question if you don't mind. Any tips on handling code blocks? I read a few of your articles and your code blocks are perfect. My code blogs have this weird coloring issue! (some part of the code are assigned random colors)

2
·
vaibhav kumar
vaibhav kumar
Jan 1, 2021

I only give proper spacing between blocks and mention the language name for each block. Also I first write my articles in Jupyter notebook, adjust the markdown accordingly and then copy paste into the blog

Nisarg Kapkar

2
·
Nisarg Kapkar
Nisarg Kapkar
Author
·Jan 1, 2021

vaibhav kumar

Thank you! I didn't know you could mention the language in blocks!

3
·
Al Murray
Al Murray
May 10, 2021

got a link to the anvil app?

·
Dvernitskiy Andrey
Dvernitskiy Andrey
Jun 2, 2021

Hello. 6B does not work. With the original file input.mp4 also does not work, output.mp4 is created but it is always the same size 23k and does not open. Although the frames in input_frames output_frames u2net_results are rendered correctly, there is some problem when assembling the video outv.write (i)

·
Social Finesse
Social Finesse
Jun 8, 2021

Hey man I need your help! Great work on this by the way it's amazing for us video editors, but i'm having trouble near the last part of the code. I'm definitely not an avid coder here at all so let me know what I'm doing wrong. Everything looks like it activated correctly but when I get towards this part:

  • Removing the background from all frames and saving them

When I try to run that code, this error comes up:


NameError Traceback (most recent call last)

<ipython-input-7-ad0006e31003> in <module>() 32 ht,wd,l=final_img.shape 33 sz=(wd,ht) ---> 34 img_array.append(final_img)

NameError: name 'img_array' is not defined

From that point on, I am totally stuck here and can't finish the process because I don't know what this means or how to fix it. However, from what I can see, everything before that has activated successfully.

If you know how to fix this part for me, I'd greatly appreciate it! Thank you

·
·1 reply
hu xuan
hu xuan
Dec 30, 2021

I met the same problem:"NameError: name 'img_array' is not defined".①At first,I thought the package PIL was not imported successfully.I added "from PIL import Image" to the first line of the cell.However,it didn't work.②Then,given that the problem concerning "img_array",I added "img_array = []" before line 34(around line 29).It seemed to start working without error,the size of output.mp4 is only about 20K.After a while,I found that I fogot the "append()" function is used to add a new object to the end of the list.The addition of "img_array = []" was wrong.It is wise to add it just before the "for" loop(around line 2).③ However,new error jumped out:"error: (-209:Sizes of input arguments do not match) The operation is neither ‘array op array’ (where arrays have the same size and the same number of channels), nor ‘array op scalar’, nor ‘scalar op array’ in function ‘cv::arithm_op’".It means that the sizes do not match?After I deleted "img_array = []" and "from PIL import Image",the cell began to work properly. It is a strange error that does not report an error when used alone.I don't know exactly what went wrong, so I wrote down the process of solving it. I hope it will help you. Good luck!

Here is my cell: for i in range(count):

#u2netreusult u2netresult=cv2.imread('/content/gdrive/MyDrive/background_removal_DL/test_data/videos/u2net_results/input'+str(i)+'.png')

#original original=cv2.imread('/content/gdrive/MyDrive/background_removal_DL/test_data/videos/input_frames/input'+str(i)+'.png')

#subimage subimage=cv2.subtract(u2netresult,original) cv2.imwrite('/content/gdrive/MyDrive/background_removal_DL/test_data/videos/output_frames/output'+str(i)+'.png',subimage)

#subimage subimage=Image.open('/content/gdrive/MyDrive/background_removal_DL/test_data/videos/output_frames/output'+str(i)+'.png')

#original original=Image.open('/content/gdrive/MyDrive/background_removal_DL/test_data/videos/input_frames/input'+str(i)+'.png')

subimage=subimage.convert("RGBA") original=original.convert("RGBA")

subdata=subimage.getdata() ogdata=original.getdata()

newdata=[] for i in range(subdata.size[0]*subdata.size[1]): if subdata[i][0]==0 and subdata[i][1]==0 and subdata[i][2]==0: newdata.append((255,255,255,0)) else: newdata.append(ogdata[i]) subimage.putdata(newdata) subimage.save('/content/gdrive/MyDrive/background_removal_DL/test_data/videos/output_frames/output'+str(i)+'.png',"PNG")

final_img=cv2.imread('/content/gdrive/MyDrive/background_removal_DL/test_data/videos/output_frames/output'+str(i)+'.png') ht,wd,l=final_img.shape sz=(wd,ht) img_array.append(final_img)

·
Khadim Hussain
Khadim Hussain
Oct 5, 2021

great article learned a lot!!!!!

·
Aashish Bhandari
Aashish Bhandari
Apr 21, 2022

Fantastic Job on the article. But please change the variable for second loop under 6B (Removing the background from all frames and saving them). This is causing issue later where only a single image is being saved and overridden after conversion to RGBA

·