pal-robotics / aruco_ros

Software package and ROS wrappers of the Aruco Augmented Reality marker detector library
MIT License
448 stars 306 forks source link

Multi Marker Detection problem #62

Closed ChunJyeBehBeh closed 4 years ago

ChunJyeBehBeh commented 5 years ago

Hello, I have wrote a subscriber which subscribe to /aruco_marker_publisher/markers_list to get the detected marker id array.

Here is the code part in my subscriber (Code Part 1):

void detectionCallback (const std_msgs::UInt32MultiArray::ConstPtr& msg)
{
    for(std::vector<unsigned int>::const_iterator it = msg->data.begin(); it != msg->data.end(); ++it)
    {   
        //printf("%d\n",*it);
        marker_list[i] = *it;
        i++;
    }
    printf("Number of detected marker is %d\n",i);
    i=0;
    printf("Length of Marker List is %lu\n",sizeof(marker_list)/sizeof(marker_list[0]));
    printf("First marker in Marker List is %d\n",marker_list[0]);
    status = 1;
    printf("Status : %d\n",status);

    return;
}

After getting the data, I would like to compare the array whether some certain id has been detected or not.

Something like this (Code Part 2):

while(status)
    {   
        int id;
        int checking=0;
        std::cout<<"Enter the marker id you want to check"<<"\n";
        std::cin>>id;
        std::cout<<"Check wether Marker %d is detected or not?"<<"\n";

        for (int k=0;k<=i;k++)
        {
            if(marker_list[k]==id)
            {
                printf("Yes!\n");
                checking =1;    
            }
        }
        if(checking==0)
        {
            printf("The marker %d is not detected.\n",id);
        }
        status=0;
    }

My problem is when I run the code, it keep stuck in code part 1, it won't run the code part 2 for me. May I know how to solve it?