-
Notifications
You must be signed in to change notification settings - Fork 39
Improc #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Improc #86
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <memory> | ||
#include <string> | ||
|
||
#include "opencv2/core/core.hpp" | ||
#include <opencv2/core/core.hpp> | ||
#include <opencv2/objdetect.hpp> | ||
#include <opencv2/highgui.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
|
||
using namespace std; | ||
using namespace cv; | ||
|
||
class Detector { | ||
public: | ||
static std::shared_ptr<Detector> CreateDetector(const std::string& name); | ||
|
||
virtual bool Init(const std::string& model_file_path) = 0; | ||
virtual void Detect(const cv::Mat& frame, std::vector<cv::Rect>& objects, | ||
std::vector<double>& scores) = 0; | ||
}; | ||
|
||
class CascadeDetector : public Detector { | ||
public: | ||
virtual bool Init(const std::string& model_file_path); | ||
virtual void Detect(const cv::Mat& frame, std::vector<cv::Rect>& objects, | ||
std::vector<double>& scores); | ||
|
||
protected: | ||
cv::CascadeClassifier detector; | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include <iostream> | ||
#include "detection.hpp" | ||
|
||
|
||
using namespace std; | ||
using namespace cv; | ||
|
||
const char* kOptions = | ||
"{ i image | <none> | image to process }" | ||
"{ v video | <none> | video to process }" | ||
"{ c camera | <none> | camera to get video from }" | ||
"{ m model | <none> | path to detector file }" | ||
"{ h ? help usage | | print help message }"; | ||
|
||
int main(int argc, const char** argv) { | ||
// Parse command line arguments. | ||
CommandLineParser parser(argc, argv, kOptions); | ||
|
||
// If help option is given, print help message and exit. | ||
if (parser.get<bool>("help")) { | ||
parser.printMessage(); | ||
return 0; | ||
} | ||
|
||
CascadeDetector detector; | ||
//("../test/test_data/detection/cascades/intel_logo_cascade.xml"); | ||
detector.Init("/home/luba/github/itseez-ss-2016-practice/test/test_data/detection/cascades/unn_old_logo_cascade.xml"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Надо передать модель через параметры командной строки. |
||
|
||
cv::Mat frame1; | ||
std::vector<cv::Rect> objects; | ||
std::vector<double> scores; | ||
|
||
/*if(parser.has("v")){ | ||
std::string filePath; | ||
filePath = parser.get("v"); | ||
cv::VideoCapture video(filePath); | ||
|
||
while(true){ | ||
video >> frame1; | ||
detector.Detect(frame1, objects, scores); | ||
} | ||
} | ||
else if(parser.has("i")){ | ||
std::string filePath; | ||
filePath = parser.get("i"); | ||
cv::Mat input = cv::imread(filePath); | ||
detector.Detect(input, objects, scores); | ||
} | ||
else if(parser.has("c")){ | ||
|
||
CvCapture* capture = cvCreateCameraCapture(CV_CAP_ANY); | ||
assert( capture ); | ||
IplImage* frame=0; | ||
cvNamedWindow("capture", CV_WINDOW_AUTOSIZE); | ||
printf("[i] press Esc for quit!\n\n"); | ||
while(true) {// получаем кадр | ||
frame = cvQueryFrame(capture); | ||
detector.Detect(frame1, objects, scores); | ||
cvShowImage("capture", frame); | ||
char c = cvWaitKey(33); | ||
if (c == 27) { // нажата ESC | ||
break; | ||
} | ||
} | ||
cvReleaseCapture( &capture ); | ||
cvDestroyWindow("capture"); | ||
} | ||
else if(parser.has("m")){ | ||
std::string filePathDetector; | ||
filePathDetector = parser.has("m"); | ||
detector.Init( filePathDetector); | ||
}*/ | ||
|
||
CvCapture* capture = cvCreateCameraCapture(CV_CAP_ANY); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тип |
||
assert( capture ); | ||
IplImage* frame=0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Для представления изображения используется тип |
||
cvNamedWindow("capture", CV_WINDOW_AUTOSIZE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Аналогично это старая версия, новая версия |
||
printf("[i] press Esc for quit!\n\n"); | ||
while(true) {// получаем кадр | ||
frame = cvQueryFrame(capture); | ||
detector.Detect(frame1, objects, scores); | ||
cvShowImage("capture", frame); | ||
char c = cvWaitKey(33); | ||
if (c == 27) { // нажата ESC | ||
break; | ||
} | ||
} | ||
cvReleaseCapture( &capture ); | ||
cvDestroyWindow("capture"); | ||
|
||
|
||
|
||
return 0; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <opencv/cv.hpp> | ||
#include <opencv2/core.hpp> | ||
#include <image_processing.hpp> | ||
|
||
#include "opencv2/core.hpp" | ||
|
||
using namespace std; | ||
using namespace cv; | ||
|
||
const char* kAbout = | ||
"This is an empty application that can be treated as a template for your " | ||
"own doing-something-cool applications."; | ||
|
||
const char* kOptions = | ||
"{ @image | <none> | image to process }" | ||
"{ gray | | convert ROI to gray scale }" | ||
|
@@ -48,8 +43,6 @@ void onMouse(int event, int x, int y, int flag, void* param) | |
int main(int argc, const char** argv) { | ||
// Parse command line arguments. | ||
CommandLineParser parser(argc, argv, kOptions); | ||
parser.about(kAbout); | ||
|
||
|
||
// If help option is given, print help message and exit. | ||
if (parser.get<bool>("help")) { | ||
|
@@ -61,7 +54,11 @@ int main(int argc, const char** argv) { | |
// Do something cool. | ||
cv::namedWindow("input"); | ||
cv::setMouseCallback("input", onMouse); | ||
cv::Mat input = cv::imread("/home/luba/Downloads/Lenna.jpg"); | ||
std::string filePath; | ||
if (parser.has("@image")){ | ||
filePath = parser.get<std::string>("@image"); | ||
} | ||
cv::Mat input = cv::imread(filePath); | ||
cv::Mat input_copy; | ||
cv::Rect rect; | ||
while(true) | ||
|
@@ -70,14 +67,14 @@ int main(int argc, const char** argv) { | |
|
||
if(mouseCallbackState.is_selection_started && !mouseCallbackState.is_selection_finished) { | ||
rect = cv::Rect(mouseCallbackState.point_first.x, mouseCallbackState.point_first.y, | ||
mouseCallbackState.point_second.x - mouseCallbackState.point_first.x, | ||
mouseCallbackState.point_second.y - mouseCallbackState.point_first.y); | ||
mouseCallbackState.point_second.x - mouseCallbackState.point_first.x, | ||
mouseCallbackState.point_second.y - mouseCallbackState.point_first.y); | ||
} | ||
cv::rectangle(input_copy, rect, cv::Scalar(90, 108, 70)); | ||
cv::rectangle(input_copy, rect, cv::Scalar(255, 0, 100)); | ||
cv::imshow("input", input_copy); | ||
char c = cv::waitKey(39); | ||
if (c == 27) | ||
break; | ||
char c = cv::waitKey(33); | ||
if (c == 27) | ||
break; | ||
} | ||
ImageProcessorImpl processor; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Что-то форматирование поплыло. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,30 @@ | ||
#include "detection.hpp" | ||
|
||
#include <iostream> | ||
#include "detection.hpp" | ||
|
||
using std::string; | ||
using std::shared_ptr; | ||
using namespace cv; | ||
|
||
shared_ptr<Detector> Detector::CreateDetector(const string& name) { | ||
std::cerr << "Failed to create detector with name '" << name << "'" | ||
<< std::endl; | ||
return nullptr; | ||
if (name == "cascade") { | ||
return std::make_shared<CascadeDetector>(); | ||
} | ||
} | ||
|
||
|
||
bool CascadeDetector::Init(const std::string &model_file_path) { | ||
detector.load(model_file_path); | ||
return detector.empty(); | ||
} | ||
|
||
void CascadeDetector::Detect(const cv::Mat &frame, std::vector<cv::Rect> &objects, std::vector<double> &scores) { | ||
if (!detector.empty() ) { | ||
std::vector<int> sc; | ||
detector.detectMultiScale(frame, objects, sc); | ||
std::copy(sc.begin(), sc.end(), scores.begin()); | ||
} | ||
else { | ||
std::cerr << "Error"; | ||
exit(-1); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему этот файл оказался в ветке с лабораторной работой по обработке?!