agrawal-rohit / opencv-facial-filters

Real-time selfie filters using facial keypoints regression and opencv

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Index Out Of Range when running Demo.py

Raja-Salman-Tariq opened this issue · comments

Hi ! Your work's really interesting ! I was trying to run your demo.py though on my computer, but the programme crashed saying :

Traceback (most recent call last):
File "demo.py", line 75, in
img_copy[top_lip_coords[1]+i+y-20, left_lip_coords[0]+j+x-60] = santa_filter[i,j]
IndexError: index 480 is out of bounds for axis 0 with size 480

I suppose that this might have something to do with
(A) that I'm an absolute noob ( still hoping my issue isn't too naive), and
(B) frame size generated by my webcam is 640x480 ?

I also commented out some stuff from your training.py and read_data.py (which I felt weren't being used in the demo - they needed the training/test datasets) but am confident that's not the source of the issue.

Could you please guide where I might need to make changes so that the filter images are appropriately scaled and apply to my webcam's frames (and do not out-size them)?

Eager to hear from you, thank you for bearing with me !

I've used the below lines of code to see if I can get my cam's resolution upped (so I can at least with the glasses only ) using the following:
image

I verified if this is supported via :
image

This has had no effect though.

Edit: The glasses filter is working though, since its within my default resolution, but its quite glitchy...

Hey @Raja-Salman-Tariq! I think you're correct about it being a video resolution issue. I was using a 1280x720 video feed from my webcam, while you are using a 640x480. This means that the manual pixel adjustments I was making for my feed, would not work for yours out of the box (as you can see from the error you're getting).

IndexError: index 480 is out of bounds for axis 0 with size 480

What this error is trying to tell you is that you are trying to access an index that is greater than your video frame array. There are 2 ways you can deal with this:

  1. You can stand farther away from your camera, which would make sure that the top_lip_coords and left_lip_coords (Used for the beard filter) are not near the edge of the video feed.
  2. You can reduce and tweak the values around the top_lip_coords (i.e. i, y, and 20) and left_lip_coords (i.e. j, x, 60).

Hope this helps :)