Guest User

Untitled

a guest
May 22nd, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. import pandas as pd
  5. import os
  6.  
  7. #printing files to check path
  8. for f in os.listdir('/Users/pk/Desktop/snapchat/Train/third-party'):
  9. print(f)
  10.  
  11. ###### Loading classifier
  12. eyes_detect= cv2.CascadeClassifier('/Users/pk/Desktop/snapchat/Train/third-party/frontalEyes35x16.xml')
  13. #eyes_detect=cv2.CascadeClassifier(cv2.data.haarcascades + 'frontalEyes35x16.xml')
  14. print(type(eyes_detect))
  15. #nose_detect= cv2.CascadeClassifier('nose.xml')
  16.  
  17. #Loading images
  18. im_mush= cv2.imread('/Users/pk/Desktop/snapchat/Train/mustache.png')
  19. im_glasses= cv2.imread('/Users/pk/Desktop/snapchat/Train/glasses.png')
  20. print('im_mush',im_mush.shape)
  21. print('im_glasses',im_glasses.shape)
  22.  
  23. im_jamie_before=cv2.imread('/Users/pk/Desktop/snapchat/Train/Jamie_Before.jpg')
  24.  
  25. print('im_jaimie',im_jamie_before.shape)
  26.  
  27. eye=eyes_detect.detectMultiScale(im_jamie_before,1.3,5)
  28.  
  29. for e in eye:
  30. x_eyes,y_eyes,w_eyes,h_eyes=e
  31. cv2.rectangle(im_jamie_before,(x_eyes,y_eyes),(x_eyes+w_eyes,y_eyes+h_eyes),(0,255,255),2)
  32.  
  33. #cv2.rectangle(im_jamie_before,(x_eyes,y_eyes),(x_eyes+w_eyes,y_eyes+h_eyes),(0,255,255),2)
  34.  
  35.  
  36. cv2.imshow('jaimie',im_jamie_before)
  37. key_pressed=cv2.waitKey(0)
  38. if key_pressed==ord('q'):
  39. cv2.destroyAllWindows()
  40.  
  41.  
  42. Output-
  43. Parikshits-MacBook-Pro:~ pk$ python3 /Users/pk/Desktop/snapchat/filter.py
  44. frontalEyes35x16XML.zip
  45. frontalEyes35x16.xml
  46. Nose18x15.xml
  47. 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 &)'
  48. > Invalid HAAR feature (expected: 'rw.r.x + rw.r.width <= W'), where
  49. > 'rw.r.x + rw.r.width' is 22
  50. > must be less than or equal to
  51. > 'W' is 16
  52.  
  53.  
  54. The above exception was the direct cause of the following exception:
  55.  
  56. Traceback (most recent call last):
  57. File "/Users/pk/Desktop/snapchat/filter.py", line 9, in <module>
  58. eyes_detect= cv2.CascadeClassifier('/Users/pk/Desktop/snapchat/Train/third-party/frontalEyes35x16.xml')
  59. SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set
Add Comment
Please, Sign In to add comment