error: (-2) The node does not represent a user object (unknown type?) in function cvRead [closed]
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!
your cascade file does not look, like the final result should. can it be, this is simply the last "stagexx.xml" from the training, renamed ?
Hi Berak, Thanks for responding. I checked the xml file and this is the "cascade.xml" file not the stage one. I also think it seems too short, but I don't know what caused that. I have 2000 negative images and 2000 positive images ( it's simply pasting 1 positive image on top of the negative images). I applied opencv_createsamples.exe to created the positives.
" it's simply pasting 1 positive image on top of the negative images"
well, that approach won't produce anything accurate, but you still should get a syntactically correct cascade out of it.
i can only guess, but yours seems not to be the final one, it either stopped with an error, or you ctrl^C 'ed it.
clean the folder with the temp stages & params, and trry again.