예제 #1
0
파일: Video.cpp 프로젝트: BioFoV/BioFoV
/**
 * @brief Video::convertToEvent
 * @param path
 * @return
 */
EventPtr Video::convertToEvent(std::string path){
	cv::Mat shot;
	FramePtr frame;
	EventPtr event;

	unsigned int j=0;
	int framecount=0;

	double tmpPos = getFramePos();
	setFramePos(0);

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

	while(getNextFrame(shot)){
		emit progressChanged(j);

		if (event.isNull()){
			event = EventPtr(new Event(this));
		}
		// create new frame
		frame = FramePtr(new Frame(this, shot, path));
		// add frame to event
		event->addFrame(frame);
		framecount ++;
		j++;
	}

	setFramePos(tmpPos);

	return event;
}
예제 #2
0
파일: Video.cpp 프로젝트: BioFoV/BioFoV
/**
 * @brief calibrate Calibrates the camera based on this Video.
 *
 * If this Video has enough chessboard pattern frames on it, and they are
 * described by the arguments given to the function, the function will
 * calibrate the video and after the call, all other player implemented
 * functions that ask for a frame will have an undistorted frame.
 *
 * @param nBoards Maximum number of boards to be detected.
 * After this number, it stops. Use frameStep to skip frames if there are a
 * lot of frames with similar pattern positions.
 * @param frameStep Steps frames to avoid similar ones.
 * @param boardW Number of inner corners of the pattern, on width.
 * @param boardH Number of inner corners of the pattern, on height.
 * @param iterations Number of iterations to be passed to the BackgroundSubtractor object. 1~5 is normally enough.
 * @param flags
 */
void Video::calibrate(int nBoards, int frameStep, int boardW,
					  int boardH, int iterations, unsigned int flags) {

	// Rewind to the beginning
	setFramePos(0);

//	if (cam != NULL){
//		delete cam;
//	}
	cam = new Camera(this, boardW, boardH);
	cam->set_calib_flags(flags);
	cam->calibrate(nBoards, frameStep, iterations);

	// Rewind again
	setFramePos(0);
}
예제 #3
0
파일: Video.cpp 프로젝트: BioFoV/BioFoV
bool Video::getPrevFrame(cv::Mat &frame){
	double tempPos = getFramePos();
	if (tempPos > 0){
		setFramePos(tempPos-1);
		return getFrame(frame);
	} else {
		return false;
	}
}
예제 #4
0
파일: Video.cpp 프로젝트: BioFoV/BioFoV
bool Video::getFrame(cv::Mat &frame){
	if(!check_cap()){
		return false;
	}
	setFramePos(getFramePos()-1);
	if(cap.read(frame)){
		if(isCalibrated()){
			frame = cam->undistort(frame);
		}
		applyDrawables(frame);
		return true;
	}
	else{
		return false;
	}
}
예제 #5
0
파일: Plots.cpp 프로젝트: ablwr/qctools
//---------------------------------------------------------------------------
void Plots::setCursorPos( int newFramePos )
{
    setFramePos( newFramePos );

    for ( size_t streamPos = 0; streamPos < m_fileInfoData->Stats.size(); streamPos++ )
        if ( m_fileInfoData->Stats[streamPos] && m_plots[streamPos] )
        {
            const double x = m_fileInfoData->Stats[streamPos]->x[m_dataTypeIndex][framePos(streamPos)];

            size_t type = m_fileInfoData->Stats[streamPos]->Type_Get();

            for ( int i = 0; i < PerStreamType[type].CountOfGroups; ++i )
                if (m_plots[streamPos][i])
                m_plots[streamPos][i]->setCursorPos( x );
        }

    m_scaleWidget->setScale( m_timeInterval.from, m_timeInterval.to);
    m_scaleWidget->update();

    replotAll();
}
예제 #6
0
파일: Video.cpp 프로젝트: BioFoV/BioFoV
/**
 * @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;
}
예제 #7
0
파일: Video.cpp 프로젝트: BioFoV/BioFoV
bool Video::stepBackwards(){
	return setFramePos(getFramePos()-1);
}
예제 #8
0
파일: Video.cpp 프로젝트: BioFoV/BioFoV
bool Video::stepForward(){
	return setFramePos(getFramePos()+1);
}