Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- import matplotlib.pyplot as plt
- import pandas as pd
- import os
- #printing files to check path
- for f in os.listdir('/Users/pk/Desktop/snapchat/Train/third-party'):
- print(f)
- ###### Loading classifier
- eyes_detect= cv2.CascadeClassifier('/Users/pk/Desktop/snapchat/Train/third-party/frontalEyes35x16.xml')
- #eyes_detect=cv2.CascadeClassifier(cv2.data.haarcascades + 'frontalEyes35x16.xml')
- print(type(eyes_detect))
- #nose_detect= cv2.CascadeClassifier('nose.xml')
- #Loading images
- im_mush= cv2.imread('/Users/pk/Desktop/snapchat/Train/mustache.png')
- im_glasses= cv2.imread('/Users/pk/Desktop/snapchat/Train/glasses.png')
- print('im_mush',im_mush.shape)
- print('im_glasses',im_glasses.shape)
- im_jamie_before=cv2.imread('/Users/pk/Desktop/snapchat/Train/Jamie_Before.jpg')
- print('im_jaimie',im_jamie_before.shape)
- eye=eyes_detect.detectMultiScale(im_jamie_before,1.3,5)
- for e in eye:
- x_eyes,y_eyes,w_eyes,h_eyes=e
- cv2.rectangle(im_jamie_before,(x_eyes,y_eyes),(x_eyes+w_eyes,y_eyes+h_eyes),(0,255,255),2)
- #cv2.rectangle(im_jamie_before,(x_eyes,y_eyes),(x_eyes+w_eyes,y_eyes+h_eyes),(0,255,255),2)
- cv2.imshow('jaimie',im_jamie_before)
- key_pressed=cv2.waitKey(0)
- if key_pressed==ord('q'):
- cv2.destroyAllWindows()
- Output-
- Parikshits-MacBook-Pro:~ pk$ python3 /Users/pk/Desktop/snapchat/filter.py
- frontalEyes35x16XML.zip
- frontalEyes35x16.xml
- Nose18x15.xml
- cv2.error: OpenCV(4.2.0) /Users/travis/build/skvark/opencv-python/opencv/modules/objdetect/src/cascadedetect.cpp:569: error: (-2:Unspecified error) in function 'bool cv::HaarEvaluator::Feature::read(const cv::FileNode &, const cv::Size &)'
- > Invalid HAAR feature (expected: 'rw.r.x + rw.r.width <= W'), where
- > 'rw.r.x + rw.r.width' is 22
- > must be less than or equal to
- > 'W' is 16
- The above exception was the direct cause of the following exception:
- Traceback (most recent call last):
- File "/Users/pk/Desktop/snapchat/filter.py", line 9, in <module>
- eyes_detect= cv2.CascadeClassifier('/Users/pk/Desktop/snapchat/Train/third-party/frontalEyes35x16.xml')
- SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set
Add Comment
Please, Sign In to add comment