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

Практика 5. Перов Дима. #127

Open
wants to merge 8 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 added data/dogs/Airedale, Airedale terrier.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 added data/dogs/Australian terrier.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 added data/dogs/Chihuahua.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 added data/dogs/Doberman, Doberman pinscher.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 added data/dogs/English foxhound.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 added data/dogs/Eskimo dog, husky.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 added data/dogs/French bulldog.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 added data/dogs/German short-haired pointer.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 added data/dogs/Ibizan hound, Ibizan Podenco.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/dogs/Mexican hairless.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 added data/dogs/Newfoundland, Newfoundland dog.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 added data/dogs/Pomeranian.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 added data/dogs/Rottweiler.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 added data/dogs/Saint Bernard, St Bernard.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 added data/dogs/Samoyed, Samoyede.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 added data/dogs/Sealyham terrier, Sealyham.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 added data/dogs/Weimaraner.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 added data/dogs/basenji.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 added data/dogs/boxer.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 added data/dogs/bull mastiff.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 added data/dogs/chow, chow chow.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 added data/dogs/collie.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 added data/dogs/dalmatian, coach dog, carriage dog.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/dogs/miniature schnauzer.jpg
Binary file added data/dogs/pug, pug-dog.jpg
Binary file added data/dogs/redbone.jpg
Binary file added data/dogs/standard schnauzer.jpg
Binary file added data/dogs/wire-haired fox terrier.jpg
24 changes: 24 additions & 0 deletions include/classificator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,28 @@ class Classificator
public:
vector<string> classesNames;
virtual Mat Classify(Mat image) = 0 {}
};



class DnnClassificator :Classificator
{
private:
string model, config, labels;
int width, height, swapRB;
Scalar mean;
Net net;
int backendId;
int targetId;
Mat blob;
double scale;
int ddepth;
bool crop;


public:
DnnClassificator(string pthModel, string pthConfig, string pthLabels, int inputWidth, int inputHeight,
Scalar myMean = (0, 0, 0, 0), int mySwapRB = 0);
virtual Mat Classify(Mat image);

};
58 changes: 58 additions & 0 deletions samples/practice1_PEROV_DIMA.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#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);
Mat res(image.size(), CV_8UC3);
Mat res1(image.size(), CV_8UC1);

// Filter image

GrayFilter myFilter;
ResizeFilter myResizeFilter(parser.get<int>("width"), parser.get<int>("height"));

res = myResizeFilter.ProcessImage(image);
res1 = myFilter.ProcessImage(res);

// Show image

imwrite("res.jpg", res1);
imshow("image", res1);
waitKey();

return 0;
}
101 changes: 101 additions & 0 deletions samples/practice2_PEROV_DIMA.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#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 model_path(parser.get<String>("model_path"));
String config_path(parser.get<String>("config_path"));
String path_label(parser.get<String>("label_path"));
int width(parser.get<int>("width"));
int height(parser.get<int>("heigth"));
Scalar mean(parser.get<Scalar>("mean"));
int swapRB(parser.get<int>("swap"));

DnnClassificator dnn(model_path, config_path,
path_label, width , height, mean, swapRB);

Mat image = imread(imgName);
Mat prob;
//Image classification

prob = dnn.Classify(image);

//Show result
Point classIdPoint;
double confidence;
minMaxLoc(prob.reshape(1, 1), 0, &confidence, 0, &classIdPoint);

int classId = classIdPoint.x;

std::cout << "Class: " << classId << '\n';
std::cout << "Confidence: " << confidence << '\n';

std::string name;

std::ifstream in("../../CV-SUMMER-CAMP/data/squeezenet1.1.labels");
int count = 0;
if (in.is_open())
{
while (getline(in, name))
{
if (count == classId)
{
break;
}
count++;

}
}
in.close();



Mat res = image;
putText(res, "Class: "+to_string(classId), Point(30, 30), FONT_HERSHEY_COMPLEX_SMALL, 0.8, Scalar(200, 200, 250));
putText(res, "Confidence: " + to_string(confidence), Point(30, 60), FONT_HERSHEY_COMPLEX_SMALL, 0.8, Scalar(200, 200, 250));
putText(res, name, Point(30, 90), FONT_HERSHEY_COMPLEX_SMALL, 0.8, Scalar(200, 200, 250));


imshow("image", res);
waitKey();
return 0;
}
Loading