1
This commit is contained in:
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Xmake cache
|
||||||
|
.xmake/
|
||||||
|
build/
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# MacOS Cache
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
|
||||||
38
src/main.cpp
Normal file
38
src/main.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(int argc, const char* argv[]){
|
||||||
|
cv::Mat img = cv::imread("armor.jpg", cv::IMREAD_COLOR);
|
||||||
|
|
||||||
|
if (img.empty()) {
|
||||||
|
std::cerr << "Failed to load image!" << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int height = img.rows; // 480
|
||||||
|
int width = img.cols; // 720
|
||||||
|
|
||||||
|
int th = 128; // 亮度阈值
|
||||||
|
|
||||||
|
cv::Mat out = cv::Mat::zeros(height, width, CV_8UC1);
|
||||||
|
|
||||||
|
for (int j = 0; j < height; j++){
|
||||||
|
for (int i = 0; i < width; i++){
|
||||||
|
// 注意:OpenCV默认是BGR顺序
|
||||||
|
uchar val = (uchar)(
|
||||||
|
img.at<cv::Vec3b>(j,i)[0] * 0.0722 + // B
|
||||||
|
img.at<cv::Vec3b>(j,i)[1] * 0.7152 + // G
|
||||||
|
img.at<cv::Vec3b>(j,i)[2] * 0.2126 // R
|
||||||
|
);
|
||||||
|
|
||||||
|
out.at<uchar>(j,i) = (val < th) ? 0 : 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cv::imshow("RESULT", out);
|
||||||
|
cv::waitKey(0);
|
||||||
|
cv::destroyAllWindows();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
15
xmake.lua
Normal file
15
xmake.lua
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
add_rules("mode.debug", "mode.release")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
set_languages("c++11")
|
||||||
|
set_optimize("faster")
|
||||||
|
|
||||||
|
add_requires("cmake::OpenCV", {alias = "opencv", system = true})
|
||||||
|
|
||||||
|
set_policy("generator.compile_commands", true)
|
||||||
|
|
||||||
|
target("hello-cv")
|
||||||
|
set_kind("binary")
|
||||||
|
add_packages("opencv")
|
||||||
|
add_files("src/*.cpp")
|
||||||
Reference in New Issue
Block a user