Ask Your Question
0

i am doing a project to predict age and gender using tensorflow and opencv. and how to add path for xml file.

asked 2020-07-02 22:25:07 -0600

OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale.

after running the code, webcam of PC will on but not capture any image. code is https://github.com/ashubansal005/Gend...

edit retag flag offensive close merge delete

Comments

You don't even test that videcapture. read() succeeds... that's what ret is for. Likely your videocaoture is not even opened, but your code diesn't fail in that case, it just waits for a miracle.

mvuori gravatar imagemvuori ( 2020-07-03 01:09:50 -0600 )edit

please show your code here

berak gravatar imageberak ( 2020-07-03 01:22:44 -0600 )edit

If your xml in currently directory. But you have this on your folder *GenderReco_AgeEsti\pretrained_models*. But you don't have Drive E:. You actually have on Drive C: You should change this:

CASE_PATH = "\\E:\\GenderReco_AgeEsti\\pretrained_models\\haarcascade_frontalface_alt.xml"
 WRN_WEIGHTS_PATH = "\\E:\\GenderReco_AgeEsti\\pretrained_models\\pretrained_models\\weights.18-4.06.hdf5"

To:

CASE_PATH = "haarcascade_frontalface_alt.xml"
 WRN_WEIGHTS_PATH = "weights.18-4.06.hdf5"
supra56 gravatar imagesupra56 ( 2020-07-03 07:57:32 -0600 )edit

i have tried but have the same error

Ashutosh gravatar imageAshutosh ( 2020-07-03 08:42:55 -0600 )edit

Are you certainly on Drive C: instead of Drive E:? Is xml is in currently folder?

supra56 gravatar imagesupra56 ( 2020-07-03 08:46:00 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2020-07-03 04:05:30 -0600

berak gravatar image

please remove \\ at the start here

error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale.

your cascade was not loaded correctly

edit flag offensive delete link more

Comments

i removed // but it shows this error- class 'cv2.CascadeClassifier'> returned a result with an error set

Ashutosh gravatar imageAshutosh ( 2020-07-03 08:41:34 -0600 )edit

Berak - as always - gave the solution. Your absolute path starts with \\ Pleas post the path you are using now. They way i usually do it in windows is to copy the path from the file explorer and then escape the \ character (\ becomes \\). Just make sure the initial path is valid.

If you still struggle , try to read in the file from a program and print its content to make very sure the path is valid. If you see the file content - its something else but the path.

holger gravatar imageholger ( 2020-07-04 09:46:45 -0600 )edit
0

answered 2020-07-03 09:44:33 -0600

holger gravatar image

updated 2020-07-03 09:45:27 -0600

I dont want to be blasphemic - But if you are using tensorflow - why are you working with cascades for face detection ? They are inferior to a face detection model in terms of accuracy.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-07-02 22:23:37 -0600

Seen: 600 times

Last updated: Jul 03 '20