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

Practice 2 Sedova #124

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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 not shown.
553 changes: 553 additions & 0 deletions classification/squeezenet/1.1/caffe/squeezenet1.1.prototxt

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions include/filter_SedovaSasha.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include <iostream>
#include <string>

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

using namespace cv;
using namespace std;

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;
public:
ResizeFilter(int newWidth, int newHeight);

Mat ProcessImage(Mat image);

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

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

#include "filter_SedovaSasha.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"));
String path_image = parser.get<String>("i");
Mat image = cv::imread(path_image);
GrayFilter g1;
ResizeFilter r1(200,200);
// Filter image
Mat GImage = g1.ProcessImage(image);
Mat RImage = r1.ProcessImage(image);
// Show image
imshow("Gray", GImage);
imshow("Image", image);
imshow("Resize", RImage);
waitKey();

return 0;
}
12 changes: 5 additions & 7 deletions samples/practice1.cpp → samples/practice1_SedovaSasha.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"));

Mat image = imread("unn_neuromobile.jpg");
GrayFilter g1;
// Filter image

Mat GImage = g1.ProcessImage(image);

// Show image




imshow("Gray", GImage);
waitKey();

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

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

#include "filter_SedovaSasha.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 = cv::imread("C:\\Users\\temp2019\\Desktop\\CV-SUMMER-CAMP\\data\\unn_neuromobile.jpg");
GrayFilter g1;
ResizeFilter r1(200,200);
// Filter image
Mat GImage = g1.ProcessImage(image);
Mat RImage = r1.ProcessImage(image);
// Show image
imshow("Gray", GImage);
imshow("Image", image);
imshow("Resize", RImage);
waitKey();

return 0;
}
54 changes: 54 additions & 0 deletions samples/practice2_Sedova.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#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"));


//Image classification


//Show result


return 0;
}
66 changes: 66 additions & 0 deletions samples/practice2_Sedova1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#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"));
String path_image = parser.get<String>("i");
string path_to_model = parser.get<String>("model_path");
string path_to_config=parser.get<String>("config_path");
string path_to_labesparser=parser.get<String>("label_path");
int width = 10;
//=parser.get<int>("w");
int height = 10;
//= parser.get<int>("h");
Scalar mean= Scalar(0, 0, 0, 0);
int swapRB=0;
Mat image = cv::imread(path_image);
DnnClassificator dnn_class(path_to_model, path_to_config, path_to_labesparser, width, height, mean, swapRB);

//Image classification

dnn_class.Classify(image);
//minMaxLoc(image,100,100,100,100);
//Show result
imshow("image", image);
waitKey();
return 0;
}
70 changes: 70 additions & 0 deletions samples/practice2_SedovaS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#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"));
String path_image = parser.get<String>("i");
string path_to_model = parser.get<String>("model_path");
string path_to_config=parser.get<String>("config_path");
string path_to_labesparser=parser.get<String>("label_path");
int width = 10;
//=parser.get<int>("w");
int height = 10;
//= parser.get<int>("h");
Scalar mean= Scalar(0, 0, 0, 0);
int swapRB=0;
Mat image = cv::imread(path_image);
DnnClassificator dnn_class(path_to_model, path_to_config, path_to_labesparser, width, height, mean, swapRB);
Mat dnnImage = dnn_class.Classify(image);
//Image classification
Point classIdPoint;
double confidence;
dnn_class.Classify(image);
minMaxLoc(dnnImage.reshape(1, 1), 0, &confidence, 0, &classIdPoint);
int classId = classIdPoint.x;
//Show result
imshow("image", image);
cout << "class:" << classId << "\n";
cout << "confidence:" << confidence<<"";
waitKey();
return 0;
}
23 changes: 23 additions & 0 deletions src/classificator_Sedova.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "classificator.h"
#include <opencv2/opencv.hpp>
DnnClassificator::DnnClassificator(string path_to_model, string path_to_config, string path_to_labes, int inputWidth, int inputHeight, vector<int> mean1, int flag_swapRB)
{
width = inputWidth;
height = inputHeight;
path_to_config = this->path_to_config;
path_to_labes = this->path_to_labes;
path_to_model = this->path_to_model;
Net net = readNet(path_to_model, path_to_config);
net.setPreferableBackend(0);
net.setPreferableTarget(0);

};
Mat DnnClassificator::Classify(Mat image)
{
Mat inputTensor;
Net net = readNet(path_to_model, path_to_config);
blobFromImage(image, inputTensor, 1.0, Size(width, height), mean, swapRB, false);
net.setInput(inputTensor);
inputTensor=net.forward();
return inputTensor;
}
Loading