Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/classificator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,17 @@ class Classificator
public:
vector<string> classesNames;
virtual Mat Classify(Mat image) = 0 {}
};

class DnnClassificator : public Classificator
{
String labelsPath;
int width, height;
Scalar mean;
Net net;
bool swapRB;
public:
DnnClassificator(String pathToModel, String pathToConfing, String pathToLabels,
int inputWidth, int inputHeight, Scalar mean, bool swapRB = false);
Mat Classify(Mat image) override;
};
10 changes: 10 additions & 0 deletions include/detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ class Detector
public:
virtual vector<DetectedObject> Detect(Mat image) = 0 {}
};

class DnnDetector : public Detector
{
private:
Net net;
int width, height;
public:
DnnDetector(String pathToConfig, String pathToModel, int w, int h);
vector<DetectedObject> Detect(Mat image) override;
};
61 changes: 61 additions & 0 deletions samples/practice1_Razumova_Maria.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <iostream>
#include <string>

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>

#include "filter.h"

using namespace cv;
using namespace std;

const char* cmdAbout = "Sample of OpenCV usage. ";

const char* cmdOptions =
"{ i image | <none> | image to process }"
"{ w width | <none> | width for image resize }"
"{ h height | <none> | height for image resize }"
"{ q ? help usage | <none> | print help message }";

int main(int argc, char** argv)
{
// Process input arguments
CommandLineParser parser(argc, argv, cmdOptions);
parser.about(cmdAbout);

if (parser.has("help"))
{
parser.printMessage();
return 0;
}
if (!parser.check())
{
parser.printErrors();
return 0;
}

// Load image
String imgName(parser.get<String>("image"));
Mat image = imread(imgName);

// Filter image
GrayFilter grayFilter;
Mat grayImg = grayFilter.ProcessImage(image);

// Show image
namedWindow("Show Image", WINDOW_NORMAL);
imshow("Show Image", grayImg);
waitKey();

// Filter image
ResizeFilter resizeFilter(parser.get<int>("width"), parser.get<int>("height"));
Mat resizedImage = resizeFilter.ProcessImage(image);

// Show image
imshow("Show Image", resizedImage);
waitKey();



return 0;
}
12 changes: 8 additions & 4 deletions samples/practice2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ int main(int argc, char** argv)

// Load image and init parameters
String imgName(parser.get<String>("image"));

Mat image = imread(imgName);

//Image classification

DnnClassificator dnn(parser.get<String>("model_path"), parser.get<String>("config_path"), parser.get<String>("label_path"),
parser.get<int>("w"), parser.get<int>("h"), Scalar(0, 0, 0, 0), parser.get<bool>("swap"));
Mat res = dnn.Classify(image);

//Show result


Point classIdPoint;
double confidence;
minMaxLoc(res, 0, &confidence, 0, &classIdPoint);
cout << "Class: " << classIdPoint << " confidence: " << confidence << std::endl;
return 0;
}
58 changes: 58 additions & 0 deletions samples/practice2_razumova_Maria.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <iostream>
#include <fstream>
#include <string>

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>

#include "classificator.h"

using namespace cv;
using namespace std;

const char* cmdAbout = "Sample of OpenCV usage. ";

const char* cmdOptions =
"{ i image | <none> | image to process }"
"{ w width | | image width for classification }"
"{ h heigth | | image heigth fro classification }"
"{ model_path | | path to model }"
"{ config_path | | path to model configuration }"
"{ label_path | | path to class labels }"
"{ mean | | vector of mean model values }"
"{ swap | | swap R and B channels. TRUE|FALSE }"
"{ q ? help usage | | print help message }";

int main(int argc, char** argv)
{
// Process input arguments
CommandLineParser parser(argc, argv, cmdOptions);
parser.about(cmdAbout);

if (parser.has("help"))
{
parser.printMessage();
return 0;
}
if (!parser.check())
{
parser.printErrors();
return 0;
}

// Load image and init parameters
String imgName(parser.get<String>("image"));
Mat image = imread(imgName);

//Image classification
DnnClassificator dnn(parser.get<String>("model_path"), parser.get<String>("config_path"), parser.get<String>("label_path"),
parser.get<int>("w"), parser.get<int>("h"), Scalar(0, 0, 0, 0), parser.get<bool>("swap"));
Mat res = dnn.Classify(image);

//Show result
Point classIdPoint;
double confidence;
minMaxLoc(res, 0, &confidence, 0, &classIdPoint);
cout << "Class: " << classIdPoint << " confidence: " << confidence << std::endl;
return 0;
}
60 changes: 60 additions & 0 deletions samples/practice3_Razumova_maria.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <string>
#include <iostream>

#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/dnn.hpp>
#include "detector.h"

using namespace std;
using namespace cv;
using namespace cv::dnn;

const char* cmdAbout =
"This is an empty application that can be treated as a template for your "
"own doing-something-cool applications.";

const char* cmdOptions =
"{ i image | <none> | image to process }"
"{ w width | | image width for detection }"
"{ h heigth | | image heigth for detection }"
"{ model_path | | path to model }"
"{ config_path | | path to model configuration }"
"{ label_path | | path to class labels }"
"{ mean | | vector of mean model values }"
"{ swap | | swap R and B channels. TRUE|FALSE }"
"{ q ? help usage | | print help message }";


int main(int argc, const char** argv) {
// Parse command line arguments.
CommandLineParser parser(argc, argv, cmdOptions);
parser.about(cmdAbout);

// If help option is given, print help message and exit.
if (parser.get<bool>("help")) {
parser.printMessage();
return 0;
}

// Do something cool.
// load image
String imgName(parser.get<String>("image"));
Mat image = imread(imgName);
resize(image, image, Size(parser.get<int>("w"), parser.get<int>("h")));

// image detection
DnnDetector detector(parser.get<String>("config_path"),parser.get<String>("model_path"),
parser.get<int>("w"), parser.get<int>("h"));
vector<DetectedObject> detectedObjects = detector.Detect(image);

// show image
namedWindow("Show Image", WINDOW_NORMAL);
imshow("Show Image", image);
//rectangle(image, Point(detectedObjects[0].Left, detectedObjects[0].Top), Point(detectedObjects[0].Left + image.cols - detectedObjects[0].Right, 150));
waitKey();

cout << "This is empty template sample." << endl;

return 0;
}
18 changes: 12 additions & 6 deletions samples/practice4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ class DnnObjectDetector
cur_rect = cur_rect & Rect(Point(), frame.size());
if (cur_rect.empty())
continue;

TrackedObject cur_obj(cur_rect, cur_confidence, frame_idx, -1);
res.push_back(cur_obj);
// add the cat, but ignore the dogs
if (cur_class_id == 8) {
TrackedObject cur_obj(cur_rect, cur_confidence, frame_idx, -1);
res.push_back(cur_obj);
}
// TrackedObject cur_obj(cur_rect, cur_confidence, frame_idx, -1);
// res.push_back(cur_obj);
}
return res;
}
Expand Down Expand Up @@ -220,17 +224,19 @@ int main(int argc, char** argv) {

// Drawing all detected objects on a frame by BLUE COLOR
for (const auto &detection : detections) {
cv::rectangle(frame, detection.rect, cv::Scalar(255, 0, 0), 3);
cv::rectangle(frame, detection.rect, cv::Scalar(255, 0, 0), 1);
}

// Drawing tracked detections only by RED color and print ID and detection
// confidence level.
for (const auto &detection : tracker->trackedDetections()) {
cv::rectangle(frame, detection.rect, cv::Scalar(0, 0, 255), 3);
cv::rectangle(frame, detection.rect, cv::Scalar(0, 0, 255), 1);
std::string text = std::to_string(detection.object_id) +
" conf: " + std::to_string(detection.confidence);
cv::putText(frame, text, detection.rect.tl(), cv::FONT_HERSHEY_COMPLEX,
1.0, cv::Scalar(0, 0, 255), 3);
1.0, cv::Scalar(0, 0, 255), 1);
std::string type = std::to_string(detection.frame_idx) + "type";
cv::putText(frame, type, detection.rect.br(), cv::FONT_HERSHEY_COMPLEX_SMALL, 1.0, cv::Scalar(0, 255, 255));
}

imshow("Tracking by Matching", frame);
Expand Down
Loading