Update README
This commit is contained in:
parent
3ee9eac8bf
commit
99338dad1c
|
@ -1,102 +0,0 @@
|
|||
#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, video_path;
|
||||
bool save_video;
|
||||
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 + "/";
|
||||
}
|
||||
video_path = data["video_path"];
|
||||
save_video = data["save_video"];
|
||||
}
|
||||
else
|
||||
{
|
||||
path = "./";
|
||||
save_video = false;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// Save video
|
||||
VideoWriter writer;
|
||||
if (save_video)
|
||||
{
|
||||
writer = VideoWriter(video_path, VideoWriter::fourcc('m', 'p', '4', 'v'), rate, Size(width, height), true);
|
||||
}
|
||||
|
||||
// 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);
|
||||
// write to video when it enabled
|
||||
if (save_video)
|
||||
{
|
||||
writer.write(frame);
|
||||
}
|
||||
}
|
||||
|
||||
int c = waitKey(1000 / rate);
|
||||
|
||||
if (c == 27)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (c == 99)
|
||||
{
|
||||
CollectEnabled = !CollectEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
capture.release();
|
||||
writer.release();
|
||||
destroyAllWindows();
|
||||
return 0;
|
||||
}
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
Thanks for the project author https://github.com/Makman2/GCR_CMake
|
||||
|
||||
and the author of json: https://github.com/nlohmann/json[GitHub - nlohmann/json: JSON for Modern C++](https://github.com/nlohmann/json)
|
||||
|
||||
The test for Qt5 is starting, and some example from the Qt opensource example.
|
||||
|
||||
(Actually, I forked the project for convenience)
|
||||
|
|
Loading…
Reference in New Issue