How to approach the Create Snapchat filter challenge

its only detecting one eye (even though there are clearly two eyes in the given image)
it does detect two eyes when I run it on myself (using webcam) however, not accurately

Hey @Tiya, first of all make sure you have right version of opencv, the haarcascade file is not supported correctly by later versions opencv. So first of run this command in jupyter notebook

!pip install opencv-python==3.4.2.16

Coming to how to approach problem further. you will get a good idea with the help of this ,

while reading moustache and glasses image use,
img=cv2.imread(“Train/glasses.png”,cv2.IMREAD_UNCHANGED))
print(img.shape)

You will notice that img has 4 channels and not 3. These channels are bgra. Where ‘a’ channel stores the opacity of channel. It will be greater than 0 if there is some opacity otherwise zero.

Next step is to resize this image, to the one having same width and height to that of nose/eyes detected.

Than you need to iterate on every pixels value on actual image from x to x+w and from y to y+h. And replace the pixel values to that of moustache/glasses image if ‘a’ channel value i.e. opacity value is greater than 0.

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts :blush:

i am facing issue detecting the eyes correctly

how do i scale the mustache image

the ans accuracy is coming -104%?

Hey @Tiya, for resizing you need to use cv2.resize function. Also make sure you are submitting predictions for test file. If yes, than plz upload the final output image here.

what should be the size of the imgWhatsApp Image 2020-05-22 at 18.54.45

Hey @Tiya, final image is perfectly fine. Also size of the image must be same as before, make sure you do not resize image at any moment. Also next step is to flatten the image and make the csv. Also make sure you are submitting final array in bgr format and not in rgb.

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush:

i did this but am still getting -104%

Hey @Tiya, plz upload your ipynb after saving it on google drive and sharing the link here.

https://drive.google.com/drive/folders/1AXZkuZFAHHeA_HfFSKIby3SPTpo9T8IQ

Hey @Tiya, you did everything fine, but after formation of final output image, the order of values was completely messed up.

Just change those lines to these, and you will be able to achieve 96 which is maximum accuracy,

print(output.shape)
cv2.imshow("image", output)
cv2.imwrite("outputimage.jpeg", output)

output_np = np.array(output)
output_b = output_np[:, :, 0]
output_g = output_np[:, :, 1]
output_r = output_np[:, :, 2]

output_b = output_b.flatten()
output_g = output_g.flatten()
output_r = output_r.flatten()

out = np.stack([output_b, output_g, output_r])
out = out.reshape((-1, 3))

out_df = pd.DataFrame(out, columns=['Channel 1', 'Channel 2', 'Channel 3'])
out_df.to_csv('outputfile.csv', index=False, index_label=False)

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush:

Sorry but the ans accuracy is still -104%

Hey @Tiya, I have submitted the file formed by the same code and I have achieved 96% accuracy.

I have messaged the code with the changes i previously recommended. Here is the link to that personal messsage as well.

http://discuss.codingblocks.com/t/re-how-to-approach-the-create-snapchat-filter-challenge/63788?u=s18crx0120

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.