Hi
I am trying to run the code below but it always fails as described. I am not sure what I am doing incorrectly there, but the code is very simple.
std::vector<Rect> detectFacesInImage(Mat& img)
{
std::vector<Rect> faces;
CascadeClassifier cascade;
std::string f = "haarcascades//haarcascade_frontalface_default.xml";
if (cascade.load(f) == true)
{
cascade.detectMultiScale(img, faces);
return faces;
}
return faces;
}
At this point, the image is already converted to grayscale. While running
cascade.detectMultiScale(img, faces);
an error is thrown.
This used to work so I have a suspicion that it is due to
Windows 11
or because of my graphic card
or both
I used to run this without problems before using Windows 10 and a different hardware set.
Is there anything I am missing here?
Thanks for the help
Daniel
berak
January 9, 2024, 8:52am
2
zlogdan:
an error is thrown.
which is ? you probably want to tell us ! …
1 Like
Hi
I apologize, I forgot to add this information.
Exceção gerada em 0x00007FFA9543567C em diImage.exe: Exceção do Microsoft C++: cv::Exception no local de memória 0x000000C373DAD130.
"diImage.exe" (Win32): Carregado "C:\Windows\System32\opencl.dll".
"diImage.exe" (Win32): Carregado "C:\Windows\System32\DXCore.dll".
"diImage.exe" (Win32): Carregado "C:\Windows\System32\AppXDeploymentClient.dll".
"diImage.exe" (Win32): Carregado "C:\Windows\System32\dxgi.dll".
"diImage.exe" (Win32): Carregado "C:\Windows\System32\ResourcePolicyClient.dll".
"diImage.exe" (Win32): NĂŁo carregado "C:\Windows\System32\ResourcePolicyClient.dll"
"diImage.exe" (Win32): Carregado "C:\Windows\System32\directxdatabasehelper.dll".
"diImage.exe" (Win32): NĂŁo carregado "C:\Windows\System32\directxdatabasehelper.dll"
"diImage.exe" (Win32): NĂŁo carregado "C:\Windows\System32\dxgi.dll"
"diImage.exe" (Win32): Carregado "C:\Windows\System32\nvopencl.dll".
"diImage.exe" (Win32): Carregado "C:\Windows\System32\nvapi64.dll".
Exceção gerada em 0x0000000000000000 em diImage.exe: 0xC0000005: violação de acesso ao executar o local 0x0000000000000
It is an access violation exception.
zlogdan:
//
that’s an invalid path.
learn about the “working directory”, and in which working dir your process actually executes. this is how relative paths are resolved.
also: load the cascade XML once at the start of the program, not every time you want to detect.
1 Like
Hi Crackwitz,
Yes, I have the working folder running under that relative path.
However, the standard C++ way of using paths is using a double “\”, but as you said, I made a mistake. I used the wrong escape sequence “//” ( You may forgive me because I work with both windows and Linux ), usually, compilers would write this warning.
>C:\Users\Administrador\Documents\GitHub\ImageProcessing\opcvwrapper.cpp(823,21): warning C4129: 'h': sequĂŞncia de escape de caractere nĂŁo reconhecida
Also:
cascade.load(f) returned true before, meaning that it was properly loaded, which does not happen if I use a single “/”
Edit: I had also checked the existence of the path using c++17
#include <filesystem>
namespace fs = std::filesystem;
bool file_exists(const std::string& file)
{
return fs::exists(file);
}
Edit 2:
it does not work with a single /
std::string f = “haarcascades\haarcascade_frontalface_default.xml”;
I even copied it to the working directory
Same error.
regards
Daniel
I can’t read this language but I can see the cv::Exception
.
catch the exception and print it. put a try-catch around the entire program.
1 Like
that exception is thrown when I run this code:
auto axes = CvPlot::plotImage(clone);
cv::Mat mat = axes.render(clone.size().width, clone.size().height);
CvPlot::show(title, axes);
waitKey(0);
This is a graph library wrapper written for openCV , but this exception does not stop the program execution.
But thanks for your help. It looks like something at my hardware causes the error probably. Because I used to run this code on another computer.
Thanks
Daniel
well what does the cv::exception
say ? it’s got a message text attached to it. you have not shared this piece of information yet.
zlogdan
January 9, 2024, 10:04pm
10
That exception cannot be captured. At least I cannot use a try catch to grab it. However, it does not work if I remove the code from the library and use imshow instead. There is a try catch that already does it. I have appreciated your help in this case, but it does look like something on my graphic board.
why? it’s a cv::Exception
. it’s made to be caught.
1 Like
zlogdan
January 10, 2024, 5:18pm
12
The exception is thrown internally inside CvPlot::show(title, axes). I think the code in the library simply ignores the exception so that is why I cannot capture it. Visual Studio shows us in the debug mode.
try {
auto axes = CvPlot::plotImage(clone);
cv::Mat mat = axes.render(clone.size().width, clone.size().height);
CvPlot::show(title, axes);
waitKey(0);
}
catch (cv::Exception& e)
{
std::cerr << e.msg << std::endl;
}