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
Binary file added data/apple.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
553 changes: 553 additions & 0 deletions data/classification/squeezenet/1.1/caffe/squeezenet1.1.prototxt

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions include/classificator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@ class Classificator
public:
vector<string> classesNames;
virtual Mat Classify(Mat image) = 0 {}
};

class DnnClassificator : public Classificator
{
public:
string modelPath, configPath, labelsPath;
int width, height;
bool swapRB;
Scalar mean;
Net net;

DnnClassificator(string _modelPath, string _configPath, string _labelsPath,
int inputWidth, int inputHeight, Scalar _mean = (0, 0, 0, 0), bool _swapRB = false);
Mat Classify(Mat image);
};
9 changes: 5 additions & 4 deletions include/detectedobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

struct DetectedObject
{
int Left;
int Right;
int Top;
int Bottom;
int xLeftBottom;
int yLeftBottom;
int xRightTop;
int yRightTop;
int uuid;
double score;
std::string classname;
};
18 changes: 18 additions & 0 deletions include/detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ class Detector
public:
virtual vector<DetectedObject> Detect(Mat image) = 0 {}
};

class DnnDetector : public Detector
{
public:
string modelPath, configPath, labelsPath;
vector<string> labels;
int width, height, numObj;
bool swapRB;
double scale;
Scalar mean;
Net net;


DnnDetector(string _modelPath, string _configPath, string _labelsPath,
int inputWidth, int inputHeight, Scalar _mean = (0, 0, 0, 0), bool _swapRB = false, double scale = 1.0);

vector<DetectedObject> Detect(Mat image);
};
22 changes: 17 additions & 5 deletions include/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,35 @@ class Filter
public:
virtual Mat ProcessImage(Mat image) = 0 {}
};

class GrayFilter : Filter
{
private:

public:
Mat ProcessImage(Mat image);
};

class ResizeFilter : Filter
{
private:
int width;
int height;
int width;
int height;
public:
ResizeFilter(int newWidth, int newHeight);
Mat ProcessImage(Mat image);


};


class MixFilter : Filter
{
private:
int n;
public:
MixFilter(int N);
Mat ProcessImage(Mat image);

};
14 changes: 6 additions & 8 deletions samples/practice1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ int main(int argc, char** argv)

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


// Filter image

// Show image
cv::imshow("image", src);
waitKey(0);

// Show image





return 0;
}
74 changes: 74 additions & 0 deletions samples/practice1_IVAN_VIKHREV.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#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 }"
"{ f filter | <none> | choose your filter(0 - resize , 1 - gray, 2 - random )}"
"{ n number | <none> | number of parts }"
"{ q ? help usage | <none> | print help message }";

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

int filter = 0, n =0 ;
if (parser.has("help"))
{
parser.printMessage();
return 0;
}

if (parser.has("filter")) {
filter = parser.get<int>("filter");
}
if (parser.has("number")) {
n = parser.get<int>("number");
}
if (!parser.check())
{
parser.printErrors();
return 0;
}

// Load image
String imgName(parser.get<String>("image"));
GrayFilter g;
ResizeFilter r(parser.get<int>("width"), parser.get<int>("height"));
MixFilter m(n);
cv::Mat src, dst;
src = imread(imgName);
// Filter image

switch (filter)
{
case 0:
dst = r.ProcessImage(src);
break;
case 2:
dst = m.ProcessImage(src);
break;
default:
dst = g.ProcessImage(src);
break;
}
// Show image
cv::imshow("image", src);
cv::imshow("image2", dst);
waitKey(0);

return 0;
}
102 changes: 102 additions & 0 deletions samples/practice2_IVAN_VIKHREV.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#include <iostream>
#include <fstream>
#include <string>
#include <fstream>

#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"));
String modelPath = parser.get<String>("model_path");
String configPath = parser.get<String>("config_path");
String labelsPath = parser.get<string>("label_path");
int width = parser.get<int>("width");
int height = parser.get<int>("heigth");
Scalar mean = parser.get<Scalar>("mean");
bool swapRB = parser.get<bool>("swap");

DnnClassificator dcl(modelPath, configPath, labelsPath, width, height, mean, swapRB);/*parser.get<String>("model_path"), parser.get<String>("config_path"),
parser.get<string>("label_path"), parser.get<int>("width"), parser.get<int>("height"),
parser.get<Scalar>("mean"), parser.get<int>("swap"));*/

Mat image = imread(imgName);
Mat prob;
Point classIdPoint[5] = { (0,0), (0,0), (0,0), (0,0) ,(0,0) };
double confidence[5] = { 0,0,0,0,0 };
int classId[5] = { 0,0,0,0,0 };
//Image classification
prob = dcl.Classify(image);
//Show result
Mat tmp = prob.reshape(1, 1);
for (int i = 0; i < 5; i++) {
minMaxLoc(tmp, 0, &confidence[i], 0, &classIdPoint[i]);
tmp.at<float>(0, classIdPoint[i].x) = 0;
classId[i] = classIdPoint[i].x;
}
std::string name;
std::ifstream in("../../CV-SUMMER-CAMP/data/squeezenet1.1.labels");

for (int i = 0; i < 5; i++) {
int count = 0;
in.seekg(0, ios::beg);
if (in.is_open())
{
while (getline(in, name))
{
if (count == classId[i])
{
break;
}
count++;

}
}
string objClass = "Class: " + std::to_string(classId[i]) + " " + name;
string conf = "Confidence: " + std::to_string(confidence[i]);
putText(image, objClass, Size(0, 20+i*40), FONT_HERSHEY_COMPLEX_SMALL, 1,
Scalar(71, 99, 255), 1, 2);
putText(image, conf, Size(0, 40+i*40), FONT_HERSHEY_COMPLEX_SMALL, 1,
Scalar(71, 99, 255), 1, 2);

}
in.close();
imshow("win", image);
waitKey(0);
return 0;
}
Loading