C++ CvSeq Accessing arrays that are stored

核能气质少年 提交于 2019-12-20 05:51:50

问题


The program I am working with is currently able to draw rectangles onto peoples heads as they move below the camera that is pointing down at them. What I am now struggling to do is to use these stored coordinates so that I can track the rectangles as they move slightly between each of the frames. Here is the specific function that I am using to do this:

void FindHeads(cv::Mat Img, vector<RECT>* detectBox)
{
    CvMemStorage* m_storage;
    m_storage = cvCreateMemStorage(0);//The default size of the open space

    CvSeq *m_first_seq = NULL;
    CvSeq *m_prev_seq = NULL;
    CvSeq *m_seq = NULL;

    CvPoint pt1, pt2;//Painted box two vertices

    cv::Mat inputcopy;
    Img.copyTo(inputcopy);//Copy the Image so that contour function can be used on it
    IplImage* pp = &IplImage(inputcopy);//Type conversion, Mat would not work
                //////////////////////////////////////////////////////////////////
    cvClearMemStorage(m_storage);
    cvFindContours(pp, m_storage, &m_first_seq, sizeof(CvContour), CV_RETR_LIST);//Find all contours

    for (m_seq = m_first_seq; m_seq; m_seq = m_seq->h_next)
    {
        CvContour* cnt = (CvContour*)m_seq;
        pt1.x = (cnt->rect.x);//Draw a box
        pt1.y = (cnt->rect.y);
        pt2.x = (cnt->rect.x + cnt->rect.width);
        pt2.y = (cnt->rect.y + cnt->rect.height);

        cv::rectangle(img_8bit, pt1, pt2, cv::Scalar(255, 255, 0), -1); //This draws the rectangles

        cv::imshow("8Bit", img_8bit);//This shows the image with rectangles drawn on

        RECT head;
        head.left = pt1.x;
        head.right = pt2.x;
        head.top = pt1.y;
        head.bottom = pt2.y;
        detectBox->push_back(head);
        std::cout << &detectBox[1];
    }
    //////////////////////////////////////////////////////////////////////////
    cvReleaseMemStorage(&m_storage);//Free up space
}

This was not developed by me and hence my confusion, I am also new to C++. What i have been trying to do, is inserting pause functions and trying to print out the data that is stored in m_storage, m_first_seq, and detectBox, because these are where I think the relevant data is being stored, and also trying to find out what dimensions the arrays are (I keep getting size of 8?)

And also, even if i was able to access the coordinates of a rectangle in one of the frames (using the pt1 and 2 x/y), how would I store these values such that they are not overwritten in the next frames when new rectangles are drawn?

This is what the rectangles look like on the frame: (Note there are a varying number from 1 to +- 10)

来源:https://stackoverflow.com/questions/39790017/c-cvseq-accessing-arrays-that-are-stored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!