The method of ensuring that the camera obtains different images in opencv

When using opencv to process video streams under Ubuntu, because the camera frame rate cannot keep up (the camera module is running in another thread, and the frame rate is too low), the algorithm will process some of the same images and return the same results. The result is returned to the servo, which may cause the servo to crash.
Three solutions come to mind:

  1. Use a camera with a high frame rate, but due to financial problems, the implementation of this plan is postponed;
    . Determine whether the returned value is the same, if the returned data is exactly the same, there is a relatively high degree of confidence that this is the result returned by the same image;
    . Before processing, judge whether the images obtained by the camera are the same, because when the camera obtains images in real time, even if the camera does not understand, the obtained images are not exactly the same at the pixel level, so we can judge the two adjacent images before processing. Whether the images are exactly the same to ensure that the data given to the servo is normal data; the
    pseudo-code for the third scheme is as follows:
    if (!m_frame_store.empty()) //The last image was not empty
    {
    long long int diff_counts = 0; / /Statistical value of different pixels
    int frame_element_size = m_frame_store.total(); //Total number of pixels
    const int diff_counts_upper = 10; //The upper limit of different values, if it exceeds, it is considered as a different image
    for (int i = 0; i < frame_element_size; i++)
    {
    if (m_frame_store.data[i] != frame.data[i])
    {
    diff_counts++;
    if (diff_counts > diff_counts_upper) //If different image features are met, stop traversing
    break;
    }
    }
    if (diff_counts > diff_counts_upper)
    {
    frame.copyTo(m_frame_store);
    m_same_frame_count = 0;
    return 1;
    }
    else //Does not meet different image features
    {
    m_same_frame_count++; //If the number of iterations reaches the upper limit, the camera is considered disconnected and the buffer area is not updated
    if (m_same_frame_count > m_same_frame_count_upper)
    restartCamera( );
    return 2;
    }
    }
    else
    {
    frame.copyTo(m_frame_store);
    m_same_frame_count = 0;
    return 1;
    }`

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325370207&siteId=291194637