Comments (3)
I have figured out a way to get images from the webcam. I modified the video.cpp and video.h file by adding a constructor to open a video device.
#include<stdio.h>
#include <string>
#include <vector>
using std::string;
using std::vector;
Video::Video(int device) : cap(device)
{
if (!cap.isOpened())
return;
}
void Video::ShowVideo() const {
const string& video_path = path;
const vector<string>& image_files = all_frames;
int annotated_frame_index = 0;
// For the 0th annotation in this video, get the start and end frames.
const int start_frame = annotations[0].frame_num;
const int end_frame = annotations[annotations.size() - 1].frame_num;
// Iterate over all frames in this video.
for (size_t image_frame_num = start_frame; image_frame_num <= end_frame; ++image_frame_num) {
// Load the image.
const string& image_file = video_path + "/" + image_files[image_frame_num];
cv::Mat image = cv::imread(image_file);
//overwrite image with what is read from camera after adjustments
// Get the frame number for the next annotation.
const int annotated_frame_num = annotations[annotated_frame_index].frame_num;
bool has_bounding_box = false;
// Check if the annotation frame number corresponds to the image frame number.
if (annotated_frame_num == image_frame_num) {
// Draw the annotation on the image.
const BoundingBox& box = annotations[annotated_frame_index].bbox;
box.DrawBoundingBox(&image);
has_bounding_box = true;
// Incremrent the annotation index.
if (annotated_frame_index < annotations.size() - 1) {
annotated_frame_index++;
}
}
// Show the image with the annotation.
if(!image.data ) {
printf("Could not open or find image %s\n", image_file.c_str());
} else {
cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE );// Create a window for display.
cv::imshow( "Display window", image ); // Show our image inside it.
cv::waitKey(1); // Wait for a keystroke in the window
}
} // For all frames in video
}
void Video::LoadFirstAnnotation(int* first_frame, cv::Mat* image,
BoundingBox* box) const {
LoadAnnotation(0, first_frame, image, box);
}
void Video::LoadAnnotation(const int annotation_index,
int* frame_num,
cv::Mat* image,
BoundingBox* box) const {
// Get the annotation corresponding to this index.
const Frame& annotated_frame = annotations[annotation_index];
// Get the frame number corresponding to this annotation.
*frame_num = annotated_frame.frame_num;
*box = annotated_frame.bbox;
const string& video_path = path;
const vector<string>& image_files = all_frames;
if (image_files.empty()) {
printf("Error - no image files for video at path: %s\n", path.c_str());
return;
} else if (*frame_num >= image_files.size()) {
printf("Cannot find frame: %d; only %zu image files were found at %s\n", *frame_num, image_files.size(), path.c_str());
return;
}
// Load the image corresponding to this annotation.
//const string& image_file = video_path + "/" + image_files[*frame_num];
cap >> frame;
*image = frame;
/*
if (!image->data) {
printf("Could not find file: %s\n", image_file.c_str());
}*/
}
bool Video::FindAnnotation(const int frame_num, BoundingBox* box) const {
// Iterate over all annotations.
for (size_t i = 0; i < annotations.size(); ++i) {
const Frame& frame = annotations[i];
// Check if the annotation frame matches the desired frame.
if (frame.frame_num == frame_num) {
// If we found a match, return the corresponding annotation.
*box = frame.bbox;
return true;
}
}
return false;
}
bool Video::LoadFrame(const int frame_num, const bool draw_bounding_box,
const bool load_only_annotation, cv::Mat* image,
BoundingBox* box) const {
const string& video_path = path;
const vector<string>& image_files = all_frames;
// Load the image for this frame.
if (!load_only_annotation) {
//const string& image_file = video_path + "/" + image_files[frame_num];
cap >> frame;
*image = frame;
}
// Find the annotation (if it exists) for the desired frame_num.
const bool has_annotation = FindAnnotation(frame_num, box);
// Draw the annotation (if it exists) on the image.
if (!load_only_annotation && has_annotation && draw_bounding_box) {
box->DrawBoundingBox(image);
}
// Return whether we found an annotation for this frame.
return has_annotation;
}```
```#ifndef VIDEO_H
#define VIDEO_H
#include "helper/bounding_box.h"
#include <opencv/cv.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
// An image frame and corresponding annotation.
struct Frame {
int frame_num;
BoundingBox bbox;
};
// Container for video data and the corresponding frame annotations.
class Video {
public:
Video(int device);
// For a given annotation index, get the corresponding frame number, image,
// and bounding box.
void LoadAnnotation(const int annotation_index, int* frame_num, cv::Mat* image,
BoundingBox* box) const;
// Find and return the first frame with an annotation in this video.
void LoadFirstAnnotation(int* first_frame, cv::Mat* image,
BoundingBox* box) const;
// For a given frame num, find an annotation if it exists, and return true.
// Otherwise return false.
// If load_only_annotation = false, also load the image.
// If draw_bounding_box = true, draw the annotation on the image.
bool LoadFrame(const int frame_num,
const bool draw_bounding_box,
const bool load_only_annotation,
cv::Mat* image,
BoundingBox* box) const;
// Show video with all annotations.
void ShowVideo() const;
// Path to the folder containing the image files for this video.
std::string path;
// Name of all image files for this video (must be appended to path).
std::vector<std::string> all_frames;
// Bounding box annotations for a subset of frames in this video.
// Note that the length of this vector may be different from the length of the vector of image filenames,
// if only a strict subset of video frames were labeled.
std::vector<Frame> annotations;
cv::VideoCapture cap;
cv::Mat frame;
private:
// For a given frame num, find an annotation if it exists, and return true.
// Otherwise return false.
bool FindAnnotation(const int frame_num, BoundingBox* box) const;
void capture(cv::VideoCapture cp);
};
// A collection of videos.
struct Category {
std::vector<Video> videos;
};
#endif // VIDEO_H
But I am getting the following error at,
cap >> frame;
template argument deduction/substitution failed:
/src/loader/video.cpp:131:13: note: cannot convert ‘((const Video)this)->Video::cap’ (type ‘const cv::VideoCapture’) to type ‘const cv::FileNode&’
cap >> frame;*
from goturn.
I am working on it. @tdlshashi
from goturn.
@ujsyehao @tdlshashi Have you completed this task? can you share with me if it's done?
from goturn.
Related Issues (20)
- Make error HOT 1
- Attempting to use an MPI routine before initializing MPI HOT 1
- Segmentation fault HOT 3
- stuck with basic issue HOT 1
- The Annotation cannot be loaded
- Understanding the ground truth HOT 1
- integrate GOTURN in the VOT toolkit
- How to deal with error accumulation?
- train without init model?
- Train on Images Only HOT 1
- How to combine GOTURN with another online algorithm?
- Why didn't my loss drop in training?
- 26048 Segmentation fault (core dumped) HOT 1
- Run tracker on single video file
- ‘caffe::Net’ is not a template HOT 3
- undefined reference
- location of annotation in alov300++ dataset is incorrect
- What is the performance for tiny moving objects?
- Segmentation fault on running the tracker test
- The link to pretrained tracker model is invalid. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goturn.