Установил opencv как здесь описано
https://www.linuxhint.com/how-to-instal ... on-ubuntu/
создал файл facecj.cpp как в мануале
Code: Select all
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
const char* keys =
{
"{i|input| |The source image}"
"{o|outdir| |The output directory}"
"{c|cascade| |The cascade file}"
};
int main(int argc, const char** argv)
{
cv::CommandLineParser parser(argc, argv, keys);
std::string infile = parser.get<std::string>("input");
std::string outdir = parser.get<std::string>("outdir");
std::string cascade_file = parser.get<std::string>("cascade");
cv::CascadeClassifier cascade;
if (cascade_file.empty() || !cascade.load(cascade_file))
{
std::cout << cv::format("Error: cannot load cascade file! \n");
return -1;
}
cv::Mat src = cv::imread(infile);
if (src.empty())
{
std::cout << cv::format("Error: cannot load source image!\n");
return -1;
}
cv::Mat gray;
cv::cvtColor(src, gray, CV_BGR2GRAY);
cv::equalizeHist(gray, gray);
std::vector<cv::Rect> faces;
cascade.detectMultiScale(gray, faces, 1.2, 3);
cv::Mat src_copy = src.clone();
for (int i = 0; i < faces.size(); i++)
{
std::cout << faces[i];
}
return 0;
}
Code: Select all
g++ `pkg-config --cflags --libs opencv` facecj.cpp `pkg-config --libs opencv` -o facecj
Code: Select all
konstantin@server:~$ ./facecj
OpenCV Error: Bad argument (undeclared key 'input' requested) in getByName, file /home/konstantin/my_scpipts/opencv/opencv-3.2.0/modules/core/src/command_line_parser.cpp, line 136
terminate called after throwing an instance of 'cv::Exception'
what(): /home/konstantin/my_scpipts/opencv/opencv-3.2.0/modules/core/src/command_line_parser.cpp:136: error: (-5) undeclared key 'input' requested in function getByName
Aborted (core dumped)
https://github.com/opencv/opencv/blob/m ... detect.cpp
скомпилировал его и получаю вывод вида
я так понимаю, что загвоздка в синтаксисе cpp файла и возможно он не подходит для opencv 3.2.konstantin@server:~$ ./face
WARNING: Could not load classifier cascade for nested objects
ERROR: Could not load classifier cascade
This program demonstrates the cascade recognizer. Now you can use Haar or LBP features.
This classifier can recognize many kinds of rigid objects, once the appropriate classifier is trained.
It's most known use is for faces.
Usage:
./facedetect [--cascade=<cascade_path> this is the primary trained classifier such as frontal face]
[--nested-cascade[=nested_cascade_path this an optional secondary classifier such as eyes]]
[--scale=<image scale greater or equal to 1, try 1.3 for example>]
[--try-flip]
[filename|camera_index]
see facedetect.cmd for one call:
./facedetect --cascade="../../data/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml" --scale=1.3
During execution:
Hit any key to quit.
Using OpenCV version 3.2.0
Можете помочь разобраться с данной проблемой ?







