Skip to content
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

da #1

Merged
merged 6 commits into from
Jul 4, 2019
Merged

da #1

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 not shown.
553 changes: 553 additions & 0 deletions data/classification/squeezenet/1.1/caffe/squeezenet1.1.prototxt

Large diffs are not rendered by default.

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

class DnnClassificator :public Classificator {
string path_to_model, path_to_config, path_to_labels;
int width, height;
Scalar mean;
bool swap;
Net net;
public:
DnnClassificator(string ptm, string ptc, string ptl, int nwidth, int nheight, Scalar nmean = (0, 0, 0, 0), bool srb = 0);
Mat Classify(Mat image);
};
63 changes: 63 additions & 0 deletions samples/practice1_Anton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#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 }"
"{ f filter | <none> | G - gray, R - 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);
string filter;
if (parser.has("help"))
{
parser.printMessage();
return 0;
}
if (!parser.check())
{
parser.printErrors();
return 0;
}
if (parser.has("filter")) {
filter = parser.get<string>("filter");
}

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


// Filter image
if (filter.find('g') != string::npos) {
GrayFilter f;
src = f.ProcessImage(src);
}
if (filter.find('r') != string::npos) {
ResizeFilter filt(parser.get<int>("width"), parser.get<int>("height"));
src = filt.ProcessImage(src);
}
// Show image
cv::imshow("image", src);
cv::waitKey();



return 0;
}
77 changes: 77 additions & 0 deletions samples/practice2_Anton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#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"));
cv::Mat src;
src = imread(imgName);
// cv::imshow("image",src);
//waitKey();

//Image classification
string mp = parser.get<string>("model_path");
string cp = parser.get<string>("config_path");
string lp = parser.get<string>("label_path");
int wid = parser.get<int>("width");
int hei = parser.get<int>("heigth");
Scalar me = parser.get<Scalar>("mean");
int sw = parser.get<int>("swap");
Point classIdPoint;
double confidence;
DnnClassificator ds(mp, cp, lp, wid,hei, me, sw);
Mat res = ds.Classify(src);
minMaxLoc(res, 0, &confidence, 0, &classIdPoint);
int classId = classIdPoint.x;

//Show result

/*ifstream ifs("labels.labels");
int s = 0;
while (s <= classId || !ifs.eof())s++;
string buff;
getline(ifs, buff);*/
cout << "Class:" << classId<< endl;
cout << "Confidence:" << confidence << endl;


return 0;
}
Loading