Skip to content
This repository was archived by the owner on Nov 13, 2021. It is now read-only.

Commit b775fc0

Browse files
committed
add some describe
1 parent 01580bb commit b775fc0

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88
CS205_C_CPP_2020S_project_matrix
99
details look at project-matrix.md
1010
1. All code(in this project,include *.c,*.cpp,*.h,*.hpp,CMakeLists.txt,etc) based on AGPL3.0(or any later version).
11+
1112
2. All *.md files are based on CC-BY-NC-SA-4.0(or any later version).
13+
1214
3. 确保文件夹所在目录下存在`catch.hpp` `catch_main.cpp`(只需要两行,`#define CATCH_CONFIG_MAIN #include "./catch.hpp"`).
1315
然后添加到`CS205_project_2020S/src`到Cmakelist.txt中即可.
1416

17+
4.
18+
+ 单元测试: test_matrix_1.cpp
19+
+ 整体测试: test_matrix_2.cpp
20+
1521
[![AGPL3.0 Licence](https://img.shields.io/badge/License-AGPL_V3-orange)][agpl_3_0]
1622

1723
[![AGPL_V3](https://www.gnu.org/graphics/agplv3-with-text-162x68.png)][agpl_3_0]

src/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ message(STATUS " libraries: ${OpenCV_LIBS}")
99
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
1010

1111
set(CMAKE_CXX_STANDARD 17)
12-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
12+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
1313

1414
include_directories(
1515
${PROJECT_SOURCE_DIR}
@@ -18,9 +18,12 @@ include_directories(
1818

1919
add_executable(${PROJECT_NAME}
2020
./../../catch_main.cpp
21+
#./test_matrix_2.cpp
2122
./test_matrix_1.cpp
2223
./Matrix.hpp
2324
)
25+
# test_matrix_1 for unit test
26+
# test_matrix_2 for demo.
2427
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
2528

2629
add_executable(${PROJECT_NAME}_test_opencv ./opencv_matrix.cpp)

src/Matrix.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include <cmath>
3737
#include "./template_helper.h"
3838

39-
const double_t eps = std::pow(10, -5);
4039

4140
namespace Mat_pro {
4241
using cv::Mat;
@@ -45,6 +44,8 @@ namespace Mat_pro {
4544
using std::vector;
4645
using std::pow;
4746

47+
const double_t eps = std::pow(10, -5);
48+
4849
struct Matrix_Shape_Not_Match_Exception : public std::exception {
4950
char will_return[300] = "\0";
5051

@@ -1012,7 +1013,7 @@ namespace Mat_pro {
10121013
type = 6;
10131014
}
10141015
if (matrix.cols() % demen != 0) {
1015-
// TODO
1016+
throw std::invalid_argument("demension not match matrix size");
10161017
}
10171018
Mat will_return(matrix.rows(), matrix.cols() / demen, type + (demen - 1) * 7);
10181019
vector<Mat> mats;
@@ -1062,7 +1063,7 @@ namespace Mat_pro {
10621063
Matrix<double_t> Matrix<T>::Hessenberg() const {
10631064
if (!this->is_square()) {
10641065
throw std::invalid_argument("Need to ensure matrix is sequre");
1065-
return Matrix<double_t>::eye_value(this->rows(), 0);
1066+
//return Matrix<double_t>::eye_value(this->rows(), 0);
10661067
}
10671068
Matrix<double_t> left_H = Matrix<double_t>::eye(this->rows());
10681069
Matrix<double_t> right_H = Matrix<double_t>::eye(this->rows());

src/test_matrix_2.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,17 @@
2222
*/
2323
#include <complex>
2424
#include <iostream>
25-
#include <random>
26-
#include <string>
27-
#include <vector>
2825

2926
#include "./../../catch.hpp"
3027
#include "./Matrix.hpp"
3128

32-
#include <iostream>
33-
#include <string>
34-
#include <unistd.h>
35-
3629
using namespace Mat_pro;
3730
using Catch::Matchers::Equals;
3831
using std::cout;
3932
using std::endl;
4033
using std::string;
4134

42-
string getCwd();
43-
4435
TEST_CASE("test 0", "[end test]") {
45-
// CS205_C_CPP\cmake-build-debug\CS205_project_2020S\src\CS205_project_2020S
4636
Mat img = cv::imread("./3c011ba75965bcfc.jpg");
4737
if (img.empty()) {
4838
std::cout << "can not load image " << endl;
@@ -53,16 +43,14 @@ TEST_CASE("test 0", "[end test]") {
5343
auto matrix_pic1 = cv_to_mat<uint16_t>(img);
5444
cout << matrix_pic1.rows() << "\n";
5545
cout << matrix_pic1.cols() << "\n";
56-
Matrix<uint16_t> m2 = {{1, 1, 1},
57-
{1, 0, 1},
58-
{1, 1, 1}};
46+
auto m2 = Matrix<uint16_t>::values(5, 5, 1);
5947
Matrix<uint16_t> m3 = {1};
60-
auto result = matrix_pic1.convolution_mul(m2, 0, 1, 3);
61-
result = result / static_cast<uint16_t>(8);
48+
auto result = matrix_pic1.convolution_mul(m2, 4, 1, 3);
49+
result = result / static_cast<uint16_t>(25);
6250
cout << result.rows() << " " << result.cols() << " \n";
6351
cv::imwrite("store.png", img);
64-
cv::imwrite("store2.jpg", mat_to_cv(matrix_pic1, 3));
65-
cv::imwrite("store3.jpg", mat_to_cv(result, 3));
52+
cv::imwrite("store_origin.jpg", mat_to_cv(matrix_pic1, 3));
53+
cv::imwrite("store_mask.jpg", mat_to_cv(result, 3));
6654
cv::waitKey(0);
6755

6856
Mat green = cv::imread("./green.jpg");
@@ -73,7 +61,7 @@ TEST_CASE("test 0", "[end test]") {
7361
auto green_matrix = cv_to_mat<uint16_t>(green);
7462
auto red_matrix = cv_to_mat<uint16_t>(red2);
7563
auto result2 = green_matrix + red_matrix - 255;
76-
cv::imwrite("result2.jpg", mat_to_cv(result2, 3));
64+
cv::imwrite("store_add_result.jpg", mat_to_cv(result2, 3));
7765
}
7866
//
7967
//string getCwd() {

0 commit comments

Comments
 (0)