Skip to content

Commit

Permalink
Merge pull request #1 from diper1998/practice-1
Browse files Browse the repository at this point in the history
Practice 1
  • Loading branch information
pyordii authored Jul 5, 2019
2 parents 7df28ba + 4f1718d commit e3e1169
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
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;
}
27 changes: 26 additions & 1 deletion src/filter.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
#include "filter.h"
#include "filter.h"

Mat GrayFilter::ProcessImage(Mat image)
{
Mat res(image.size(), CV_8UC1);

// Filter image

cvtColor(image, res, COLOR_RGB2GRAY);

return res;
}

ResizeFilter::ResizeFilter(int newWidth, int newHeight)
{
width = newWidth;
height = newHeight;
}

Mat ResizeFilter::ProcessImage(Mat image)
{
Mat res;
resize(image, res, Size(width, height));
return res;
}

0 comments on commit e3e1169

Please sign in to comment.