Ejemplo n.º 1
0
SnapshotPtr UniformSample::getSnapshot() const {
    boost::lock_guard<boost::mutex> lock(mutex_);
    Int64Vector::const_iterator begin_itr(values_.begin());
    Int64Vector::const_iterator end_itr(values_.begin());
    std::advance(end_itr, size());
    return SnapshotPtr(new Snapshot(ValueVector(begin_itr, end_itr)));
}
Ejemplo n.º 2
0
SnapshotPtr ExpDecaySample::getSnapshot() const {
    ValueVector vals;
    vals.reserve(values_.size());
    std::lock_guard<std::mutex> rlock(mutex_);
    for(Double2Int64Map::const_iterator it = values_.begin(); it !=  values_.end(); ++it) {
    	vals.push_back(it->second);
    }
    return SnapshotPtr(new Snapshot(vals));
}
Ejemplo n.º 3
0
/**
 * @brief Automatically splits the video into several events provided the
 * given parameters.
 * @param threshold
 * @param maxcount
 * @param mincount
 * @param history
 * @param varThreshold
 * @param bShadowDetection
 * @param path
 * @return
 */
std::deque<EventPtr> Video::autoDetectEvents(double threshold,
										   double maxcount,
										   double mincount,
										   int history,
										   int varThreshold,
										   bool bShadowDetection,
										   std::string path){
	cv::Mat shot;
	FramePtr frame;
	SnapshotPtr snap;
	EventPtr event;
	std::deque<EventPtr> events;

	unsigned int j=0;
	int emptycount=0;
	int framecount=0;
	int value;
	int absoluteThreshold = threshold/100*resolution.width*resolution.height;
	int i;


	// Initialization of background subtraction
	bgSubInit(history, varThreshold, bShadowDetection);

	setFramePos(0);

	emit startProgress(0, (uint) getLengthFrames());

	while(getNextFrame(shot)){
		QCoreApplication::processEvents();
		if (toCancel){
			events.clear();
			canceled();
			return events;
		}
		bg->NewFrame(shot);
		bg->Denoise();
		emit progressChanged(j);
		value = cv::countNonZero(bg->Foreground());

		// Detected change
		if ( value > absoluteThreshold ){
			if (event.isNull()){
				event = EventPtr(new Event(this));
			}
			// create new frame
			frame = FramePtr(new Frame(this, shot, path));
			snap = SnapshotPtr(new Snapshot(frame, bg->Foreground(), path));
			// add frame to event
			event->addFrame(frame);
			event->addSnapshot(snap);
			framecount ++;
			emptycount = 0;
		}
		// Did not detect change
		else if (!event.isNull()){
			emptycount ++;
			// create new frame
			frame = FramePtr(new Frame(this, shot, path));
			snap = SnapshotPtr(new Snapshot(frame, bg->Foreground(), path));
			// add frame to event
			event->addFrame(frame);
			event->addSnapshot(snap);
			framecount ++;
			if(emptycount > maxcount){
				if (framecount - emptycount > mincount){
					// remove extra frames with no movement
					for (i = 0; i < maxcount; i++){
						event->remLastFrame();
						event->remLastSnapshot();
					}
					events.push_back(event);
				}
				event.clear();
				emptycount = 0;
				framecount = 0;
			}
		}
		j++;
	}
	// Check if Video ended in the middle of an Event.
	if (!event.isNull()){
		if (framecount > mincount){
			events.push_back(event);
		} else {
			event.clear();
		}
	}
	return events;
}