Add OpenCV test6
This commit is contained in:
parent
46dfeeabc2
commit
24c24d994b
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
cmake_minimum_required(VERSION 3.0.0)
|
||||
project(OpenCV_test5 VERSION 1.0.0)
|
||||
|
||||
#Find the opencv package
|
||||
find_package(OpenCV REQUIRED)
|
||||
|
||||
#include directories for opencv
|
||||
include_directories(${OpenCV_INCLUDE_DIRS})
|
||||
|
||||
add_executable(${PROJECT_NAME} main.cpp)
|
||||
|
||||
#Add command to generate .gitignore
|
||||
add_custom_command(TARGET ${PROJECT_NAME}
|
||||
COMMAND echo \"*\" > ${CMAKE_BINARY_DIR}/.gitignore
|
||||
COMMAND echo \"**/*\" > ${CMAKE_BINARY_DIR}/.hgignore)
|
||||
|
||||
#Add OpenCV Libraries
|
||||
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
|
|
@ -0,0 +1,66 @@
|
|||
#include <opencv2/opencv.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::string filename;
|
||||
Mat image;
|
||||
int brightless = 0;
|
||||
|
||||
// Get Filename
|
||||
std::cout << "Input Filename:";
|
||||
std::cin >> filename;
|
||||
|
||||
if (filename != "")
|
||||
{
|
||||
image = imread(filename, IMREAD_COLOR);
|
||||
if (image.empty())
|
||||
{
|
||||
std::cout << "Failed to open the image!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Mat dst = Mat::zeros(image.size(), image.type());
|
||||
Mat m = Mat::zeros(image.size(), image.type());
|
||||
namedWindow("Image brightless test", WINDOW_NORMAL);
|
||||
imshow("Image brightless test", image);
|
||||
|
||||
while (1)
|
||||
{
|
||||
int c = waitKey(1);
|
||||
if (c != -1)
|
||||
{
|
||||
std::cout << c << std::endl;
|
||||
}
|
||||
if (c == 27)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (c == 45)
|
||||
{
|
||||
if (brightless > 0)
|
||||
{
|
||||
brightless -= 5;
|
||||
}
|
||||
m = Scalar(brightless, brightless, brightless);
|
||||
add(image, m, dst);
|
||||
imshow("Image brightless test", dst);
|
||||
}
|
||||
if (c == 61)
|
||||
{
|
||||
if (brightless < 100)
|
||||
{
|
||||
brightless += 5;
|
||||
}
|
||||
m = Scalar(brightless, brightless, brightless);
|
||||
add(image, m, dst);
|
||||
imshow("Image brightless test", dst);
|
||||
}
|
||||
}
|
||||
|
||||
destroyAllWindows();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
cmake_minimum_required(VERSION 3.0.0)
|
||||
project(OpenCV_test6 VERSION 1.0.0)
|
||||
|
||||
#Find the opencv package
|
||||
find_package(OpenCV REQUIRED)
|
||||
|
||||
#include directories for opencv
|
||||
include_directories(${OpenCV_INCLUDE_DIRS})
|
||||
|
||||
add_executable(${PROJECT_NAME} main.cpp)
|
||||
|
||||
#Add command to generate .gitignore
|
||||
add_custom_command(TARGET ${PROJECT_NAME}
|
||||
COMMAND echo \"*\" > ${CMAKE_BINARY_DIR}/.gitignore
|
||||
COMMAND echo \"**/*\" > ${CMAKE_BINARY_DIR}/.hgignore)
|
||||
|
||||
#Add OpenCV Libraries
|
||||
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
|
|
@ -0,0 +1,64 @@
|
|||
#include <opencv2/opencv.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::string filename;
|
||||
Mat image, hsv_image, mask;
|
||||
int brightless = 0;
|
||||
|
||||
// Get Filename
|
||||
std::cout << "Input Filename:";
|
||||
std::cin >> filename;
|
||||
|
||||
// Load the image
|
||||
if (filename != "")
|
||||
{
|
||||
image = imread(filename, IMREAD_COLOR);
|
||||
if (image.empty())
|
||||
{
|
||||
std::cout << "Failed to open the image!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert the image to HSV color and filter the background color
|
||||
cvtColor(image, hsv_image, COLOR_BGR2HSV);
|
||||
|
||||
// Output the statistics
|
||||
double minv, maxv;
|
||||
Point minloc, maxloc;
|
||||
std::vector<Mat> mv;
|
||||
split(image, mv);
|
||||
for (int i = 0; i < mv.size(); i++)
|
||||
{
|
||||
minMaxLoc(mv[i], &minv, &maxv, &minloc, &maxloc);
|
||||
std::cout << "min:" << minv << " max:" << maxv << " minloc:"
|
||||
<< minloc << " maxloc:" << maxloc << std::endl;
|
||||
}
|
||||
Mat mean, stddev;
|
||||
meanStdDev(image, mean, stddev);
|
||||
std::cout << "mean:" << std::endl << mean << std::endl;
|
||||
std::cout << "stddev" << std::endl << stddev << std::endl;
|
||||
inRange(hsv_image, Scalar(35, 43, 46), Scalar(77, 255, 255), mask);
|
||||
namedWindow("Image Mask", WINDOW_NORMAL);
|
||||
imshow("Image Mask", mask);
|
||||
|
||||
while (1)
|
||||
{
|
||||
int c = waitKey(1);
|
||||
if (c != -1)
|
||||
{
|
||||
std::cout << c << std::endl;
|
||||
}
|
||||
if (c == 27)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
destroyAllWindows();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue