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 1 #1

Merged
merged 2 commits into from
Jul 5, 2019
Merged
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
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;
}