Add OpenCV test9
This commit is contained in:
parent
8759e9ac65
commit
cde027ffa7
|
@ -1,5 +1,6 @@
|
|||
#include "TextEditor.hh"
|
||||
#include "text_types.hh"
|
||||
#include "../json_nlohmann/json.hpp"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
|
@ -12,6 +13,10 @@ TextEditor::TextEditor()
|
|||
searchbox(Gtk::ORIENTATION_HORIZONTAL, 5),
|
||||
file_opened(false)
|
||||
{
|
||||
// Load window config from json file
|
||||
|
||||
|
||||
|
||||
// Initalize Window
|
||||
set_default_size(800, 450);
|
||||
set_icon_name("my_textedit");
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
|
||||
"files.associations": {
|
||||
"iostream": "cpp"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
cmake_minimum_required(VERSION 3.0.0)
|
||||
project(OpenCV_test9 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,85 @@
|
|||
#include <opencv2/opencv.hpp>
|
||||
#include "../../json_nlohmann/json.hpp"
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Read Config from json file
|
||||
std::string path;
|
||||
std::ifstream config_file("config_collect.json");
|
||||
if (config_file.is_open())
|
||||
{
|
||||
json data = json::parse(config_file);
|
||||
path = data["path"];
|
||||
if (path[path.length() - 1] != '/')
|
||||
{
|
||||
path = path + "/";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
path = "./";
|
||||
}
|
||||
|
||||
// Start Video Capture
|
||||
bool CollectEnabled = false;
|
||||
VideoCapture capture(0);
|
||||
if (!capture.isOpened())
|
||||
{
|
||||
std::cout << "Can't open video device!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// properties
|
||||
double rate = capture.get(CAP_PROP_FPS);
|
||||
double width = capture.get(CAP_PROP_FRAME_WIDTH);
|
||||
double height = capture.get(CAP_PROP_FRAME_HEIGHT);
|
||||
|
||||
// Information about the camera
|
||||
std::cout << "Frame Rate = " << rate << "width = " << width << "height = " << height << std::endl;
|
||||
|
||||
namedWindow("Video Capture", WINDOW_NORMAL);
|
||||
|
||||
Mat frame;
|
||||
while (1)
|
||||
{
|
||||
// read frame from video capture
|
||||
if (!capture.read(frame))
|
||||
{
|
||||
std::cout << "no video frame" << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Show the image of frame
|
||||
imshow("Video Capture", frame);
|
||||
|
||||
// Write frame to file
|
||||
static int count = 0;
|
||||
if (CollectEnabled)
|
||||
{
|
||||
count++;
|
||||
std::string filename = path + std::to_string(count) + ".jpg";
|
||||
imwrite(filename, frame);
|
||||
}
|
||||
|
||||
int c = waitKey(10);
|
||||
|
||||
if (c == 27)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (c == 99)
|
||||
{
|
||||
CollectEnabled = !CollectEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
capture.release();
|
||||
destroyAllWindows();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue