Why does assertion fail here

后端 未结 2 1051
萌比男神i
萌比男神i 2021-01-28 03:27

Why does the assertion fail here when i create a CvMat *? It does not happen with an image i load in cv::Mat using a pointer.

    struct RGB { unsig         


        
2条回答
  •  清酒与你
    2021-01-28 03:52

    You can skip the entire IplImage misery if you use cv::Mat img = cv::loadImage("blah.jpg"); Also it is better to use row ptr for going through all the pixels.
    It knows the jumps, so you don't have to worry!

    From the refman:

    If you need to process a whole row of a 2D array, the most efficient way is to get the pointer to the row first, and then just use the plain C operator []

    Be aware that if you are loading bigger images which have "jumps" in their data, your code will not work. In your situation

    cv::Mat img = cv::loadImage("blah.jpg");
    const cv::Mat& M = img;
    for(int i = 0; i < rows; i++) 
    {
        const Vec3b* Mi = M.ptr(i); 
        for(int j = 0; j < cols; j++)
        {
            const Vec3b& Mij = Mi[j];
            std::cout<<"Row="<
                                                            
提交回复
热议问题