Add file save feature

This commit is contained in:
daleclack 2022-07-15 09:19:00 +08:00
parent 5eacda9c97
commit f8516efeab
4 changed files with 67 additions and 1 deletions

View File

@ -4,9 +4,11 @@
using namespace cv; using namespace cv;
int main(int argc, char ** argv){ int main(int argc, char ** argv){
std::string filename; std::string filename, save_images;
std::cin >> filename; std::cin >> filename;
std::cout << "Save gray and hsv images? (Y/N)";
std::cin >> save_images;
// Open the image // Open the image
Mat image, image_hsv, image_gray; Mat image, image_hsv, image_gray;
@ -26,6 +28,10 @@ int main(int argc, char ** argv){
namedWindow("Gray Image", WINDOW_FREERATIO); namedWindow("Gray Image", WINDOW_FREERATIO);
imshow("Gray Image", image_gray); imshow("Gray Image", image_gray);
// Write the images
imwrite("image_gray.png", image_gray);
imwrite("image_hsv.png", image_hsv);
waitKey(0); waitKey(0);
destroyAllWindows(); destroyAllWindows();

View File

@ -0,0 +1,3 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

View File

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.0.0)
project(OpenCV_test3 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})

View File

@ -0,0 +1,39 @@
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
int main(int argc, char ** argv){
std::string filename, save_images;
std::cin >> filename;
std::cout << "Save gray and hsv images? (Y/N)";
std::cin >> save_images;
// Open the image
Mat image, image_hsv, image_gray;
image = imread(filename, IMREAD_COLOR);
if(image.empty()){
std::cout << "failed to open the image";
return -1;
}
cvtColor(image, image_hsv, COLOR_BGR2HSV);
cvtColor(image, image_gray, COLOR_BGR2GRAY);
// Show the converted images
namedWindow("Original Image", WINDOW_FREERATIO);
imshow("Original Image", image);
namedWindow("HSV Image", WINDOW_FREERATIO);
imshow("HSV Image", image_hsv);
namedWindow("Gray Image", WINDOW_FREERATIO);
imshow("Gray Image", image_gray);
// Write the images
imwrite("image_gray.png", image_gray);
imwrite("image_hsv.png", image_hsv);
waitKey(0);
destroyAllWindows();
return 0;
}