forked from itlab-vision/CV-SUMMER-CAMP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from diper1998/practice-1
Practice 1
- Loading branch information
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|