Skip to content

Commit a821e29

Browse files
author
Kirill Kornyakov
committed
Add error codes
1 parent e6cb8d3 commit a821e29

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

sample_template/application.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int Application::processFrame(const Mat& src, Mat& dst)
3737
return 0;
3838
}
3939

40-
int Application::show(const std::string &caption, const Mat& src, const Mat& dst)
40+
int Application::showFrame(const std::string &caption, const Mat& src, const Mat& dst)
4141
{
4242
if (src.rows != dst.rows || src.cols != dst.cols)
4343
{

sample_template/application.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class Application
1616

1717
int getFrame(const std::string &fileName, cv::Mat& src);
1818
int processFrame(const cv::Mat& src, cv::Mat& dst);
19-
int show(const std::string &caption, const cv::Mat& src, const cv::Mat& dst);
19+
int showFrame(const std::string &caption, const cv::Mat& src, const cv::Mat& dst);
20+
2021
private:
2122
Processing processor;
2223
};

sample_template/main.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
using namespace std;
77
using namespace cv;
88

9+
enum ErrorCode {
10+
OK,
11+
WRONG_ARGUMENTS,
12+
WRONG_INPUT,
13+
CANT_PROCESS
14+
};
15+
916
int main(int argc, const char **argv)
1017
{
1118
Application app;
@@ -15,27 +22,26 @@ int main(int argc, const char **argv)
1522
{
1623
cout << "practice2 <image_name>" << endl;
1724
cout << "<image_name> - image name for filtering" << endl;
18-
return 1;
25+
return WRONG_ARGUMENTS;
1926
}
2027

2128
Mat src;
2229
if (app.getFrame(params.imgFileName, src) != 0)
2330
{
2431
cout << "Error: \'src\' image is null or empty!" << endl;
25-
return 2;
32+
return WRONG_INPUT;
2633
}
2734

2835
Mat dst;
2936
if (app.processFrame(src, dst) != 0)
3037
{
3138
cout << "Error: Filtering failed!" << endl;
32-
return 3;
39+
return CANT_PROCESS;
3340
}
3441

35-
const std::string caption = "OpenCV Sample";
3642
char key = 0;
3743
while(key != 27) // Esc
38-
key = app.show(caption, src, dst);
44+
key = app.showFrame("OpenCV Sample", src, dst);
3945

40-
return 0;
46+
return OK;
4147
}

0 commit comments

Comments
 (0)