예제 #1
0
    std::vector<TagMatch> detectTags(const cv::Mat& image) {

        int residual = image.cols % IMAGE_U8_DEFAULT_ALIGNMENT;
        cv::Mat img_aligned;
        if (residual != 0) {
            cv::copyMakeBorder(image, img_aligned, 0, 0, (IMAGE_U8_DEFAULT_ALIGNMENT - residual) / 2, (IMAGE_U8_DEFAULT_ALIGNMENT - residual) / 2, cv::BORDER_CONSTANT, 0);
        } else {
            img_aligned = image;
        }

        cv::cvtColor(img_aligned, img_aligned, CV_RGB2GRAY);
        image_u8_t *image_u8 = fromCvMat(img_aligned);
        
        std::vector<TagMatch> tags = detectTags(image_u8);


        if (show_window) {
            cv::cvtColor(img_aligned, img_aligned, CV_GRAY2RGB);
            for (int i = 0; i < tags.size(); i++) { 

                cv::line(img_aligned, tags[i].p0, tags[i].p1, cv::Scalar(255,0,0), 2, CV_AA);
                cv::line(img_aligned, tags[i].p1, tags[i].p2, cv::Scalar(0,255,0), 2, CV_AA);
                cv::line(img_aligned, tags[i].p2, tags[i].p3, cv::Scalar(0,0,255), 2, CV_AA);
                cv::line(img_aligned, tags[i].p3, tags[i].p0, cv::Scalar(0,0,255), 2, CV_AA);

                Eigen::Vector3d x_axis(2,0,1);
                Eigen::Vector3d y_axis(0,2,1);
                Eigen::Vector3d origin(0,0,1);

                Eigen::Vector3d px = tags[i].H * x_axis;
                Eigen::Vector3d py = tags[i].H * y_axis;
                Eigen::Vector3d o  = tags[i].H * origin;

                px/= px[2];
                py/= py[2];
                o/= o[2];

                cv::line(img_aligned, cv::Point2d(o[0], o[1]), cv::Point2d(px[0], px[1]), cv::Scalar(255,0,255), 1, CV_AA);
                cv::line(img_aligned, cv::Point2d(o[0], o[1]), cv::Point2d(py[0], py[1]), cv::Scalar(255,255,0), 1, CV_AA);
            }
            cv::imshow("detections", img_aligned);
            cv::waitKey(1);
        }

        image_u8_destroy(image_u8);
        return tags;

    }
예제 #2
0
void CiSimplePose::update( ci::Surface8uRef const& surface )
{
    // No image to process
    if ( !surface )
        return;

    // Process image and get detected tags
    auto detectedTags = detectTags( surface );

    if ( detectedTags.size() )
    {
        TagEvent event;
        bool previouslyUnknownTagsFound = updateTags( detectedTags );

        if ( previouslyUnknownTagsFound )
            mSignalTagDiscovered.emit( event );

        mSignalTagUpdated.emit( event );

        mIndividualTagEventDispatcher->sendIndividualEvents( detectedTags );
    }
}
예제 #3
0
void CiSimplePose::getTagPoses( ci::Surface8uRef surface, ci::mat4 viewMatrix )
{
    detectTags( surface );
}