Skip to content

Commit da34b64

Browse files
committed
[feat] add DynamicThreshold(), Stretching(), Variance(), TwoLineIntersection()
1 parent f338475 commit da34b64

File tree

6 files changed

+435
-0
lines changed

6 files changed

+435
-0
lines changed

.gitignore

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
#others
35+
build/CMakeCache.txt
36+
build/cmake_install.cmake
37+
build/Makefile
38+
build/CMakeFiles/*
39+
build/lib/*
40+
build/bin/*
41+
build/ALL_BUILD.vcxproj
42+
build/ALL_BUILD.vcxproj.filters
43+
build/ZERO_CHECK.vcxproj
44+
build/ZERO_CHECK.vcxproj.filters
45+
build/x64
46+
build/computervision.dir
47+
build/computervision.sln
48+
build/computervision.vcxproj
49+
build/computervision.vcxproj.filters

include/common.h

+47
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <cmath>
55
#include <experimental/filesystem>
66
#include <iostream>
7+
#include <memory>
78
#include <string>
89
#include <vector>
910

@@ -23,4 +24,50 @@ static std::unique_ptr<T> make_unique(Args &&...args) {
2324
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
2425
}
2526

27+
inline int LoadFolderPath(const std::string &folder_path, std::vector<std::string> &img_path_vector, std::vector<std::string> &img_filename_vector) {
28+
std::cout << "LoadFolderPath() start" << std::endl;
29+
if (!folder_path.empty()) {
30+
if (!boost::filesystem::exists(folder_path)) {
31+
std::cout << "Folder : " << folder_path << " does not exist." << std::endl;
32+
return -1;
33+
}
34+
// boost::regex pattern(folder_path + "/[0-9]*.png");
35+
boost::filesystem::directory_iterator end_itr;
36+
for (boost::filesystem::directory_iterator itr(folder_path); itr != end_itr; ++itr) {
37+
if (boost::filesystem::is_directory(itr->status())) {
38+
} else if ((itr->path().extension() == ".png") || (itr->path().extension() == ".bmp")) {
39+
std::string imgpath = itr->path().string();
40+
// std::cout << "imgpath : " << imgpath << std::endl;
41+
img_path_vector.push_back(itr->path().string());
42+
img_filename_vector.push_back(itr->path().filename().stem().string());
43+
}
44+
// else if (boost::regex_match(itr->path().string(), pattern)){
45+
// img_path_vector.push_back(itr->path().string());
46+
// }
47+
}
48+
}
49+
std::cout << "LoadFolderPath() end" << std::endl;
50+
return 0;
51+
}
52+
53+
inline int ConvertMatToGrayscale(const cv::Mat &src, cv::Mat &gray_dst) {
54+
const int &&channel = src.channels();
55+
switch (channel) {
56+
case 1: {
57+
gray_dst = cv::Mat::zeros(src.size(), CV_8UC1);
58+
gray_dst = src.clone();
59+
break;
60+
}
61+
case 3: {
62+
gray_dst = cv::Mat::zeros(src.size(), CV_8UC1);
63+
cv::cvtColor(src, gray_dst, cv::COLOR_BGR2GRAY, 1);
64+
break;
65+
}
66+
default: {
67+
std::cout << " --> int ConvertMatToGrayscale (cv::Mat)src.channels != 1 || 3" << std::endl;
68+
return -1;
69+
}
70+
}
71+
return 0;
72+
}
2673
#endif //_COMMON_H_

include/component/image_proc.h

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef _IMAGE_PROC_H_
2+
#define _IMAGE_PROC_H_
3+
4+
#include "common.h"
5+
6+
namespace ipo {
7+
8+
enum class DynamicThresholdTypes {
9+
DYNAMIC_THRES_LIGHT = 0,
10+
DYNAMIC_THRES_DARK = 1,
11+
DYNAMIC_THRES_LIGHT_AND_DARK_INRANGE = 2,
12+
DYNAMIC_THRES_LIGHT_OR_DARK_OUTRANGE = 3,
13+
};
14+
15+
/**
16+
* @brief Calculate the diff value between subtraction of grayscale image and fuzzy image. If the value exceed the offset value, then it equal to 255, and vice versa.
17+
* @param src input image.
18+
* @param dst output image.
19+
* @param blur_ksize blurring kernel size.
20+
* @param offset diff value.
21+
* @param mode dynamic threshold mode.
22+
**/
23+
int DynamicThreshold(const cv::Mat &src, cv::Mat &dst,
24+
const int &blur_ksize, const int &offset,
25+
const DynamicThresholdTypes &mode);
26+
/**
27+
* @brief Refer to the B&C function of imageJ to stretch the pixel value
28+
* between low_value and high_value. If it exceeds high_value, it is 255, and it
29+
* is 0 if it is less than low_value.
30+
* @param src input image.
31+
* @param dst output image.
32+
* @param low_value Low threshold.
33+
* @param high_value High threshold.
34+
**/
35+
int Stretching(const cv::Mat &src, cv::Mat &dst,
36+
const int &low_value, const int &high_value);
37+
/**
38+
*
39+
**/
40+
int Variance(const cv::Mat &src, cv::Mat &dst, const int &kernel_size);
41+
cv::Point TwoLineIntersection(const cv::Point &x1_start, const cv::Point &x1_end,
42+
const cv::Point &x2_start, const cv::Point &x2_end);
43+
} // namespace ipo
44+
#endif // _IMAGE_PROC_H_

include/error_code/error_code.h

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef _ERROR_CODE_H_
2+
#define _ERROR_CODE_H_
3+
// class
4+
#endif // _ERROR_CODE_H_

main.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "component/image_proc.h"
2+
3+
// cv::Mat ImgProcTestFunc(cv::)
4+
5+
int main() {
6+
// ---load image---
7+
cv::Mat &&src = cv::imread("D:\\images\\Kenmec\\20210208\\13.png");
8+
// cv::Mat &&dst = cv::Mat::zeros(src.size(), src.type());
9+
cv::Mat dst;
10+
// std::shared_ptr<ipo::ImageProc> obj = std::make_shared<ipo::ImageProc>();
11+
ipo::DynamicThreshold(src, dst, 21, 10, ipo::DynamicThresholdTypes::DYNAMIC_THRES_LIGHT);
12+
cv::imshow("dst", dst);
13+
cv::waitKey(0);
14+
return 0;
15+
}

0 commit comments

Comments
 (0)