Add file save feature
This commit is contained in:
parent
5eacda9c97
commit
f8516efeab
|
@ -4,9 +4,11 @@
|
|||
using namespace cv;
|
||||
|
||||
int main(int argc, char ** argv){
|
||||
std::string filename;
|
||||
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;
|
||||
|
@ -26,6 +28,10 @@ int main(int argc, char ** argv){
|
|||
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();
|
||||
|
||||
|
|
|
@ -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_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})
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue