<commit_before>#include <alvar_logger/alvar_logger_node.h>
#include <sensor_msgs/image_encodings.h>
#include <cv_bridge/cv_bridge.h>

AlvarLoggerNode::AlvarLoggerNode(ros::NodeHandle &nh) : nh_(nh), it_(nh), frame_number_(0)
{
    std::string camera_info_topic;
    if (!nh_.getParam("camera_info_topic", camera_info_topic))
    {
        ROS_ERROR("Camera info topic needs to be specified");
        exit(0);
    }

    cam_ = new alvar::Camera(nh_, camera_info_topic);

    std::string log_file_name;
    if (!nh_.getParam("log_file", log_file_name))
    {
        ROS_ERROR("Log file needs to be specified");
        exit(0);
    }
    
    if (!nh_.hasParam("video_file"))
    {
        ROS_ERROR("Video file needs to be specified");
        exit(0);
    }

    file_out_.open(log_file_name.c_str());

    image_publisher_ = it_.advertise("detected_markers", 1);
    image_subscriber_ = it_.subscribe("input_image", 0, &AlvarLoggerNode::imageCallback, this);
}

AlvarLoggerNode::~AlvarLoggerNode()
{
    file_out_.close();
    delete cam_;
}

void AlvarLoggerNode::imageCallback(const sensor_msgs::ImageConstPtr &image)
{   
    if (cam_->getCamInfo_)
    {
        if (!video_writer_.isOpened())
        {
            cv::Size image_size(image->width, image->height);
            double frame_rate = 30.0;
            std::string video_file_name;
            nh_.getParam("video_file", video_file_name);
            video_writer_.open(video_file_name, CV_FOURCC('D','I','V','X'), frame_rate, image_size, true);
        }
        cv_bridge::CvImagePtr cv_image = cv_bridge::toCvCopy(image, sensor_msgs::image_encodings::BGR8);
        IplImage ipl_image = cv_image->image;
        marker_detector_.Detect(&ipl_image, cam_);                

        video_writer_.write(cv_image->image);

        cv::Mat debug_image;
        cv_image->image.copyTo(debug_image);

        for (size_t i = 0; i < marker_detector_.markers->size(); i++)
        {
            int id = (*(marker_detector_.markers))[i].GetId();
            std::vector<alvar::PointDouble> marker_corners = (*(marker_detector_.markers))[i].marker_corners_img;
            for (int i = 0; i < marker_corners.size() - 1; i++)
            {
                cv::Point start_point(marker_corners.at(i).x, marker_corners.at(i).y);
                cv::Point end_point(marker_corners.at(i + 1).x, marker_corners.at(i + 1).y);
                cv::line(debug_image, start_point, end_point, CV_RGB(255, 0, 0), 3, CV_AA, 0);
                if (i == 0)
                {
                    file_out_ << id << ", " << frame_number_ << ", " << start_point.x << ", " << start_point.y;
                }
                else
                {
                    file_out_ << ", " << start_point.x << ", " << start_point.y;
                }
            }
            cv::Point start_point(marker_corners.at(marker_corners.size() - 1).x, marker_corners.at(marker_corners.size() - 1).y);
            cv::Point end_point(marker_corners.at(0).x, marker_corners.at(0).y);
            cv::line(debug_image, start_point, end_point, CV_RGB(255, 0, 0), 3, CV_AA, 0);
            file_out_ << ", " << start_point.x << ", " << start_point.y << std::endl;
        }<commit_msg>log frame id first then  marker id<commit_after>#include <alvar_logger/alvar_logger_node.h>
#include <sensor_msgs/image_encodings.h>
#include <cv_bridge/cv_bridge.h>

AlvarLoggerNode::AlvarLoggerNode(ros::NodeHandle &nh) : nh_(nh), it_(nh), frame_number_(0)
{
    std::string camera_info_topic;
    if (!nh_.getParam("camera_info_topic", camera_info_topic))
    {
        ROS_ERROR("Camera info topic needs to be specified");
        exit(0);
    }

    cam_ = new alvar::Camera(nh_, camera_info_topic);

    std::string log_file_name;
    if (!nh_.getParam("log_file", log_file_name))
    {
        ROS_ERROR("Log file needs to be specified");
        exit(0);
    }
    
    if (!nh_.hasParam("video_file"))
    {
        ROS_ERROR("Video file needs to be specified");
        exit(0);
    }

    file_out_.open(log_file_name.c_str());

    image_publisher_ = it_.advertise("detected_markers", 1);
    image_subscriber_ = it_.subscribe("input_image", 0, &AlvarLoggerNode::imageCallback, this);
}

AlvarLoggerNode::~AlvarLoggerNode()
{
    file_out_.close();
    delete cam_;
}

void AlvarLoggerNode::imageCallback(const sensor_msgs::ImageConstPtr &image)
{   
    if (cam_->getCamInfo_)
    {
        if (!video_writer_.isOpened())
        {
            cv::Size image_size(image->width, image->height);
            double frame_rate = 30.0;
            std::string video_file_name;
            nh_.getParam("video_file", video_file_name);
            video_writer_.open(video_file_name, CV_FOURCC('D','I','V','X'), frame_rate, image_size, true);
        }
        cv_bridge::CvImagePtr cv_image = cv_bridge::toCvCopy(image, sensor_msgs::image_encodings::BGR8);
        IplImage ipl_image = cv_image->image;
        marker_detector_.Detect(&ipl_image, cam_);                

        video_writer_.write(cv_image->image);

        cv::Mat debug_image;
        cv_image->image.copyTo(debug_image);

        for (size_t i = 0; i < marker_detector_.markers->size(); i++)
        {
            int id = (*(marker_detector_.markers))[i].GetId();
            std::vector<alvar::PointDouble> marker_corners = (*(marker_detector_.markers))[i].marker_corners_img;
            for (int i = 0; i < marker_corners.size() - 1; i++)
            {
                cv::Point start_point(marker_corners.at(i).x, marker_corners.at(i).y);
                cv::Point end_point(marker_corners.at(i + 1).x, marker_corners.at(i + 1).y);
                cv::line(debug_image, start_point, end_point, CV_RGB(255, 0, 0), 3, CV_AA, 0);
                if (i == 0)
                {
                    file_out_ << frame_number_ << ", " << id << ", " << start_point.x << ", " << start_point.y;
                }
                else
                {
                    file_out_ << ", " << start_point.x << ", " << start_point.y;
                }
            }
            cv::Point start_point(marker_corners.at(marker_corners.size() - 1).x, marker_corners.at(marker_corners.size() - 1).y);
            cv::Point end_point(marker_corners.at(0).x, marker_corners.at(0).y);
            cv::line(debug_image, start_point, end_point, CV_RGB(255, 0, 0), 3, CV_AA, 0);
            file_out_ << ", " << start_point.x << ", " << start_point.y << std::endl;
        }
{'fraction_non_alphanumeric': 0.14726399007905752, 'fraction_numerical': 0.010541001395132537, 'mean_word_length': 2.545054945054945, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6619988', 'n_tokens_mistral': 2274, 'n_tokens_neox': 2150, 'n_words': 344}