Snapchat Filter

@S18CRX0120
overlay=cv2.resize(overlay,(w,h))

for i in range(overlay.shape[0]):
for j in range(overlay.shape[1]):
if(overlay[i,j,3]>0):
fullimg[y+i,x+j,:]=overlay[i,j,:-1]
what is overlay[i,j,3] denoting ,I found this code after going through discussion ,unable to understand.Help!!

Hello @Bhawna,

Can you please provide the entire code through Coding Blocks IDE.

https://colab.research.google.com/drive/1CuYiF1nS-PzG0TzoPblKrwD2ix4XKnZR#scrollTo=YpmlPmydL-ok This was the code from which I was taking help but didn’t understand this part :
overlay=cv2.resize(overlay,(w,h))

for i in range(overlay.shape[0]):
for j in range(overlay.shape[1]):
if(overlay[i,j,3]>0):
fullimg[y+i,x+j,:]=overlay[i,j,:-1]

Hello @Bhawna,

Here the overlay is the image of the glass and is a png image. If you know, png images can have transparent parts, and these transparent parts are identified using the 4th channel, the alpha channel.

Here in this code, the author has copied the content of the image in overlay to the original image pixel by pixel if that pixel’s 4th channel is > 0 meaning is not transparent.

You can read more here.

Thanks :slightly_smiling_face:

Sir here overlay[i,j,3] is showing index out of range .plz help.

Hello @Bhawna,

This error means the i or j is greater than the size of the image, or the number of channels in the image is less than 4. I suggest you debug this yourself by printing the share of the overlay or fullimg shape.
Continue in this thread if you are still facing an issue and be sure to share the entire traceback. A screenshot would be perfect.

Thanks

Yes Sir I already printed shape and have found cause of error.
Can we overwrite pixels without checking transparency??

Hello @Bhawna,

Try doing it, you will see the white background of moustache and glasses after writing.

Sir I am getting black background not white background.

@Manu-Pillai-1566551720093198 sir i am getting this

Now ,I got my mistake but I am getting only 86 % accuracy,though i tried to adjust correct position of mustache below nose.
My code https://drive.google.com/drive/folders/12CAhYJDR-T2HxRfv_o3H9fwEnT8rLAae?usp=sharing

Hi @Bhawna,

Regarding your first doubt, you should never overwrite pixels without checking for transparency (the 4th channel alpha in png), otherwise, you’ll have some weird after-effects and that beats the whole purpose of the png format (images with transparency). See these samples and you’ll understand:
transparent_overlay_10
transparent_overlay_05

Coming to your second doubt, don’t get confused by the near-perfect accuracies on the leaderboard. Those are submissions by Coding Block testers who have the actual solution available with them. These scores are achievable only by submitting the actual reference file and unachievable in reality even when using state-of-the-art methods. Your accuracy is quite respectable and you can safely move on to other challenges.

Hope this resolved your issue.
Happy Learning!

to is 86% maximum achievable score??

No, it’s not. But it’s a good score.
One common mistake in this challenge is that people create the submission .csv in rgb format (order of color channels). Please make sure your submission is in bgr order. This might increase your score significantly.

Let me know if this works.

yes ,accuracy increased and it is 98%.Thanks

can i increase 2 %more accuracy??

No Bhawna, 98% is kind of the maximum possible performance. As I told you before, 100% is possible only by submitting the original solution csv available to the Testers.

Happy to help!

ok …