Exemplo n.º 1
0
/**
 * This is the backup plan, when the normal way to find marker yields 0 result, we resort
 * to use optical flow from previous detected marker position.
 *
 * @param prev_frame previous captured frame, of 8UC1 type
 * @param frame current frame, also of 8UC1 / grayscale type
 * @param marker the previously detected Marker object, we're basically just looking at the points
 * @return true if optical flow found a candidate marker
 **/
bool MarkerDetector::opticalFlowPrediction( Mat& prev_frame, Mat& frame, Marker& marker ) {
    Mat status, error;
    vector<Point2f> new_points;
    
    /* Use sparse optical flow to predict where the points flowed to, dense version is too slow */
    calcOpticalFlowPyrLK( prev_frame, frame, marker.poly, new_points, status, error );
    
    /* Make sure that all points are detected */
    if ( sum( status ) != Scalar(4) )
        return false;
    
    /* make sure that it fits our candidates requirements */
    if( !checkPoints( new_points ))
        return false;
    
    /* just ignore it when it's already partially out of the scene */
    for( Point2f point : new_points ) {
        if( point.y <= 0 || point.x <= 0 || point.x >= frame.cols || point.y >= frame.rows )
            return false;
    }

    marker.poly.clear();
    copy( new_points.begin(), new_points.end(), back_inserter( marker.poly ));
    
    return true;
}
//------------------------------------------------------------------------
void ParameterChangesCheck::checkAllChanges (Steinberg::Vst::IParameterChanges* paramChanges)
{
	for (Steinberg::int32 paramIdx = 0; paramIdx < paramChanges->getParameterCount (); ++paramIdx)
	{
		Steinberg::Vst::IParamValueQueue* paramQueue = paramChanges->getParameterData (paramIdx);
		if (checkParameterQueue (paramQueue))
		{
			checkParameterId (paramQueue->getParameterId ());
			checkPoints (paramQueue);
		}
	}
}
Exemplo n.º 3
0
void mesh::initMesh(int num){
	gPoints.clear();
	gNormals.clear();
	gFaceCounts.clear();
	gFaceConnects.clear();

	Domain *d;
	std::vector<unsigned int > index;
	
	d=domain[num];
	for(int j=0;j<d->face_list.size();j++){
		Face *f=d->face_list[j];
		gFaceCounts.append(f->vertex_coords.size());//vertex count in face
		for(int k=0;k<f->vertex_coords.size();k++){
			if(checkPoints(f->vertex_indexs[k],index)){//ensure not replicate points
				index.push_back(f->vertex_indexs[k]);
				MPoint p(f->vertex_coords[k].x,f->vertex_coords[k].y,f->vertex_coords[k].z);
				gPoints.append(p);
			}//if
			int n=findIndex(f->vertex_indexs[k],index);
			gFaceConnects.append(n);
		}//for k
	}//for j
}
Exemplo n.º 4
0
 void operator()(const tbb::blocked_range<size_t>& r) const
 {
   checkPoints(r.begin(), r.end());
 }
Exemplo n.º 5
0
Arquivo: Diff.cpp Projeto: SCUSIT/PDAL
int Diff::execute()
{

    Options sourceOptions;
    {
        sourceOptions.add<std::string>("filename", m_sourceFile);
        sourceOptions.add<bool>("debug", isDebug());
        sourceOptions.add<boost::uint32_t>("verbose", getVerboseLevel());
    }
    boost::scoped_ptr<Stage> source(AppSupport::makeReader(sourceOptions));
    source->initialize();

    boost::uint32_t chunkSize(source->getNumPoints());
    if (m_chunkSize)
        chunkSize = m_chunkSize;
    PointBuffer source_data(source->getSchema(), chunkSize);
    boost::scoped_ptr<StageSequentialIterator> source_iter(source->createSequentialIterator(source_data));

    ptree errors;




    Options candidateOptions;
    {
        candidateOptions.add<std::string>("filename", m_candidateFile);
        candidateOptions.add<bool>("debug", isDebug());
        candidateOptions.add<boost::uint32_t>("verbose", getVerboseLevel());
    }

    boost::scoped_ptr<Stage> candidate(AppSupport::makeReader(candidateOptions));
    candidate->initialize();


    PointBuffer candidate_data(candidate->getSchema(), chunkSize);
    boost::scoped_ptr<StageSequentialIterator> candidate_iter(candidate->createSequentialIterator(candidate_data));

    if (candidate->getNumPoints() != source->getNumPoints())
    {
        std::ostringstream oss;

        oss << "Source and candidate files do not have the same point count";
        errors.put<std::string>("count.error", oss.str());
        errors.put<boost::uint32_t>("count.candidate" , candidate->getNumPoints());
        errors.put<boost::uint32_t>("count.source" , source->getNumPoints());

    }

    pdal::Metadata source_metadata = source->collectMetadata();
    pdal::Metadata candidate_metadata = candidate->collectMetadata();

    if (source_metadata != candidate_metadata)
    {
        std::ostringstream oss;

        oss << "Source and candidate files do not have the same metadata count";
        errors.put<std::string>("metadata.error", oss.str());
        errors.put_child("metadata.source", source_metadata.toPTree());
        errors.put_child("metadata.candidate", candidate_metadata.toPTree());
    }


    Schema const& candidate_schema = candidate_data.getSchema();


    Schema const& source_schema = source_data.getSchema();

    if (! ( candidate_schema == source_schema))
    {
        std::ostringstream oss;

        oss << "Source and candidate files do not have the same schema";
        errors.put<std::string>("schema.error", oss.str());
        errors.put_child("schema.source", source_schema.toPTree());
        errors.put_child("schema.candidate", candidate_schema.toPTree());

    }



    if (errors.size())
    {
        write_json(std::cout, errors);
        return 1;
    } else
    {
        // If we made it this far with no errors, now we'll
        // check the points.
        checkPoints(source_iter.get(),
                    source_data,
                    candidate_iter.get(),
                    candidate_data,
                    errors);
        if (errors.size())
        {
            write_json(std::cout, errors);
            return 1;
        }
    }

    return 0;

}
Exemplo n.º 6
0
VOID Player::turn(ProgramManager &rProgramManager, GameInfo &rGameInfo)
{
	if(rGameInfo.first == first_)
	{
		if(rGameInfo.scoredEight) rProgramManager.endGame(name_ + L" выиграл со счЄтом: " + getScoreWStr());
		else if(rGameInfo.scoredZero)
		{ 
			rGameInfo.scoredZero = FALSE;
			rGameInfo.drawCue    = FALSE;
			rGameInfo.turn       = Turns::SetZeroPos;

			rProgramManager.updateZero();
		}
		else if(rGameInfo.scoredWrong)
		{
			rGameInfo.scoredWrong = FALSE;
			rGameInfo.drawCue     = FALSE;
			rGameInfo.turn        = Turns::SetPos;
		}

		if(!copied_) 
		{
			memcpy(tmpBallsStatus_, rProgramManager.getScored(), sizeof(tmpBallsStatus_));
			memcpy(tmpBallsPos_, rProgramManager.getPoints(), sizeof(tmpBallsPos_));

			copied_ = !copied_;
		}

		if(rGameInfo.turn == Turns::SetZeroPos)
		{ 
			rProgramManager.setBallCoords(rProgramManager.getMousePos());

			rProgramManager.work(textToDraw(), PointF(0, 0), static_cast<ARGB>(Color::LightGreen), FALSE);

			if(Key(VK_END)) 
			{
				rGameInfo.turn = Turns::Blow;

				rGameInfo.drawCue = TRUE;
			}
		}
		else if(rGameInfo.turn == Turns::SetPos)
		{
			rProgramManager.setBallCoords(rProgramManager.getMousePos(), rGameInfo.wrongBall);
			rProgramManager.work(textToDraw(), PointF(0, 0), static_cast<ARGB>(Color::LightGreen), FALSE);
			
			if(Key(VK_END)) 
			{
				rGameInfo.turn = Turns::Blow;

				rGameInfo.drawCue = TRUE;
			}
		}
		else if(rGameInfo.turn == Turns::Blow) 
		{	
			if(Key(VK_SPACE))
			{
				POINT cursor = { 0, 0 };
				GetCursorPos(&cursor);		

				rProgramManager.nextMove();
				rGameInfo.turn = Turns::Step;
			}
			else rProgramManager.work(textToDraw());
		}
		else if(rGameInfo.turn == Turns::Step)
		{
			if(!rProgramManager.stopBalls()) rProgramManager.work(textToDraw());
			else
			{
				updateScore(checkScored(rProgramManager, rGameInfo));
				if(!checkPoints(rProgramManager)) if(score_ != 0) score_--;
				resetValues();
				rGameInfo.resetToNext(); 
			}		
		}
	}
	else rProgramManager.work(textToDraw(), PointF(static_cast<REAL>(rProgramManager.getMemDCWindow().width - 6 * sizestenaRIGHT), 0), static_cast<ARGB>(Color::Red), rGameInfo.drawCue);
}
Exemplo n.º 7
0
/**
 * Find a list of candidate marker from a given scene
 *
 * @param current frame, in grayscale 8UC1 format
 * @return a list of marker candidates
 **/
vector<Marker> MarkerDetector::findMarkerCandidates( Mat& frame ) {
    vector<Marker> candidates;
    
    /* Do some thresholding, in fact you should tune the parameters here a bit */
    Mat thresholded;
    threshold( frame, thresholded, 50.0, 255.0, CV_THRESH_BINARY );
    
    /* Find contours */
    vector<vector<Point>> contours;
    findContours( thresholded.clone(), contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE );
    
    for( vector<Point> contour: contours ) {
        /* Approximate polygons out of these contours */
        vector<Point> approxed;
        approxPolyDP( contour, approxed, contour.size() * 0.05, true );
        
        /* Make sure it passes our first candidate check */
        if( !checkPoints( approxed ) )
            continue;
        
        /* Do some perspective transformation on the candidate marker to a predetermined square */
        Marker marker;
        marker.matrix = Mat( markerHeight, markerWidth, CV_8UC1 );
        std::copy( approxed.begin(), approxed.end(), back_inserter( marker.poly ) );
        
        /* Apply sub pixel search */
        cornerSubPix( thresholded, marker.poly, Size(5, 5), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 40, 0.001) );
        
        /* Projection target */
        const static vector<Point2f> target_corners = {
            Point2f( -0.5f, -0.5f ),
            Point2f( +5.5f, -0.5f ),
            Point2f( +5.5f, +5.5f ),
            Point2f( -0.5f, +5.5f ),
        };
        
        /* Apply perspective transformation, to project our 3D marker to a predefined 2D coords */
        Mat projection = getPerspectiveTransform( marker.poly, target_corners );
        warpPerspective( thresholded, marker.matrix, projection, marker.matrix.size() );
        
        /* Ignore those region that's fully black, or not surrounded by black bars */
        if( sum(marker.matrix) == Scalar(0) ||
           countNonZero( marker.matrix.row(0)) != 0 ||
           countNonZero( marker.matrix.row(markerHeight - 1)) != 0 ||
           countNonZero( marker.matrix.col(0)) != 0 ||
           countNonZero( marker.matrix.col(markerWidth - 1)) != 0 ) {
            continue;
        }
        
        
        /* Find the rotation that has the smallest hex value */
        pair<unsigned int, unsigned int> minimum = { numeric_limits<unsigned int>::max(), 0 };
        vector<unsigned int> codes(markerHeight);
        unsigned int power = 1 << (markerWidth - 3);
        
        /* Rotate the marker 4 times, store the hex code upon each rotation */
        for( int rotation = 0; rotation < 4; rotation++ ) {
            stringstream ss;
            codes[rotation] = 0;
            
            for( int i = 1; i < markerHeight - 1; i++ ) {
                unsigned int code = 0;
                for ( int j = 1; j < markerWidth - 1; j++ ){
                    int value = static_cast<int>(marker.matrix.at<uchar>(i, j));
                    if( value == 0 )
                        code = code + ( power >> j );
                }
                
                ss << hex << code;
            }
            ss >> codes[rotation];
            
            if( minimum.first > codes[rotation] ) {
                minimum.first  = codes[rotation];
                minimum.second = rotation;
            }
            
            flip( marker.matrix, marker.matrix, 1 );
            marker.matrix = marker.matrix.t();
        }
        
        
        rotate( marker.poly.begin(), marker.poly.begin() + ((minimum.second + 2) % 4), marker.poly.end() );
        for( int i = 0; i < minimum.second; i++ ) {
            flip( marker.matrix, marker.matrix, 1 );
            marker.matrix = marker.matrix.t();
        }
        
        marker.code = minimum.first;
        
        candidates.push_back( marker );
    }
    
    return candidates;
}
Exemplo n.º 8
0
int Diff::execute()
{
    PointContext sourceCtx;

    Options sourceOptions;
    {
        sourceOptions.add<std::string>("filename", m_sourceFile);
        sourceOptions.add<bool>("debug", isDebug());
        sourceOptions.add<boost::uint32_t>("verbose", getVerboseLevel());
    }
    std::unique_ptr<Stage> source(AppSupport::makeReader(m_sourceFile));
    source->setOptions(sourceOptions);
    source->prepare(sourceCtx);
    PointBufferSet sourceSet = source->execute(sourceCtx);

    ptree errors;

    PointContext candidateCtx;
    Options candidateOptions;
    {
        candidateOptions.add<std::string>("filename", m_candidateFile);
        candidateOptions.add<bool>("debug", isDebug());
        candidateOptions.add<boost::uint32_t>("verbose", getVerboseLevel());
    }

    std::unique_ptr<Stage> candidate(AppSupport::makeReader(m_candidateFile));
    candidate->setOptions(candidateOptions);
    candidate->prepare(candidateCtx);
    PointBufferSet candidateSet = candidate->execute(candidateCtx);

    assert(sourceSet.size() == 1);
    assert(candidateSet.size() == 1);
    PointBufferPtr sourceBuf = *sourceSet.begin();
    PointBufferPtr candidateBuf = *candidateSet.begin();
    if (candidateBuf->size() != sourceBuf->size())
    {
        std::ostringstream oss;

        oss << "Source and candidate files do not have the same point count";
        errors.put("count.error", oss.str());
        errors.put("count.candidate", candidateBuf->size());
        errors.put("count.source", sourceBuf->size());
    }

    MetadataNode source_metadata = sourceCtx.metadata();
    MetadataNode candidate_metadata = candidateCtx.metadata();
    if (source_metadata != candidate_metadata)
    {
        std::ostringstream oss;

        oss << "Source and candidate files do not have the same metadata count";
        errors.put("metadata.error", oss.str());
        errors.put_child("metadata.source", pdal::utils::toPTree(source_metadata));
        errors.put_child("metadata.candidate", pdal::utils::toPTree(candidate_metadata));
    }

    if (candidateCtx.dims().size() != sourceCtx.dims().size())
    {
        std::ostringstream oss;

        oss << "Source and candidate files do not have the same "
            "number of dimensions";
        errors.put<std::string>("schema.error", oss.str());
        //Need to "ptree" the PointContext dimension list in some way
        // errors.put_child("schema.source", sourceCtx.schema()->toPTree());
        // errors.put_child("schema.candidate",
        //     candidateCtx.schema()->toPTree());
    }

    if (errors.size())
    {
        write_json(std::cout, errors);
        return 1;
    }
    else
    {
        // If we made it this far with no errors, now we'll
        // check the points.
        checkPoints(*sourceBuf, *candidateBuf, errors);
        if (errors.size())
        {
            write_json(std::cout, errors);
            return 1;
        }
    }
    return 0;
}