Hi all, My inviroment is windows 10, opencv 3.1, python 3.4 I'm trying to train my own Cascade using opencv_createsamples.exe and opencv_traincascade.exe. I've created a .vec file (it is loadable by opencv_createsamples) and trained a 11-stage cascade.xml file. When I try to load it in the python code, it run into an error saying "error: (-2) The node does not represent a user object (unknown type?) in function cvRead".
Here is my code:
import cv2 import numpy as np import matplotlib.pyplot as plt import time
face_cascade = cv2.CascadeClassifier('C:/Python34/opencvPracticePic/haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier('C:/Python34/opencvPracticePic/haarcascade_eye.xml')
Pen_cascade = cv2.CascadeClassifier('C:/Python34/opencvPracticePic/Pencascade.xml')
cap = cv2.VideoCapture(0)
while (cap.isOpened()): ret, frame = cap.read()
k= cv2.waitKey(16) & 0xFF == ord('q')
if k==27:
break
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray,1.3,5)
Pen = Pen_cascade.detectMultiScale(gray, 20, 20)
for (x,y,w,h) in Pen:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,255,0),2)
for (x,y,w,h) in faces:
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray= gray[y:y+h,x:x+w]
roi_color = frame[y:y+h,x:x+w]
eyes = eye_cascade.detectMultiScale(roi_gray)
for(ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
cv2.namedWindow('resized',cv2.WINDOW_NORMAL)
cv2.resizeWindow('resized',600,400)
cv2.imshow('resized',frame)
cap.release() cv2.destroyAllWindows()
Here is the self-trained cascade xml file
Here is the .vec file created by opencv_createsamples
Much thanks for any response!