Ask Your Question

Revision history [back]

OpenCV png c++ assertion failed

Hi! My Code is:

Mat temp = imread(f_name, 1);


    cout << temp.channels() << "chanels in image" << endl ;
            getch()

;
        img = CImg<unsigned char>(temp.cols, temp.rows, 1, 4);
        width = img.width();
        high = img.height();
        static int ii = 0;
            cout << "Image readed nr " << ii << endl;
        // Rewrite from opencv to CImg
        for(int l = 0 ; l < width ; l++){
            for(int ll = 0 ; ll < high ; ll++){
                img (l,ll, 0 , 0) = temp.at<cv::Vec4b>(ll,l)[0]; 
                img (l,ll, 0 , 1) = temp.at<cv::Vec4b>(ll,l)[1]; 
                img (l,ll, 0 , 2) = temp.at<cv::Vec4b>(ll,l)[2];
                img (l,ll, 0 , 3) = temp.at<cv::Vec4b>(ll,l)[3]; // aplha chanell
            }
        }

It compile well, but in runtime there is assertion failed with mat.hpp in line 537. If i commented loops everything works without result ok.

Please Do Yiou have some ideas, please ?

Best Regards, Szymsztein

click to hide/show revision 2
retagged

OpenCV png c++ assertion failed

Hi! My Code is:

Mat temp = imread(f_name, 1);


    cout << temp.channels() << "chanels in image" << endl ;
            getch()

;
        img = CImg<unsigned char>(temp.cols, temp.rows, 1, 4);
        width = img.width();
        high = img.height();
        static int ii = 0;
            cout << "Image readed nr " << ii << endl;
        // Rewrite from opencv to CImg
        for(int l = 0 ; l < width ; l++){
            for(int ll = 0 ; ll < high ; ll++){
                img (l,ll, 0 , 0) = temp.at<cv::Vec4b>(ll,l)[0]; 
                img (l,ll, 0 , 1) = temp.at<cv::Vec4b>(ll,l)[1]; 
                img (l,ll, 0 , 2) = temp.at<cv::Vec4b>(ll,l)[2];
                img (l,ll, 0 , 3) = temp.at<cv::Vec4b>(ll,l)[3]; // aplha chanell
            }
        }

It compile well, but in runtime there is assertion failed with mat.hpp in line 537. If i commented loops everything works without result ok.

Please Do Yiou have some ideas, please ?

Best Regards, Szymsztein

OpenCV png c++ assertion failed

Hi! My Code is:

Mat temp = imread(f_name, 1);


    cout << temp.channels() << "chanels in image" << endl ;
            getch()

;
        img = CImg<unsigned char>(temp.cols, temp.rows, 1, 4);
        width = img.width();
        high = img.height();
        static int ii = 0;
            cout << "Image readed nr " << ii << endl;
        // Rewrite from opencv to CImg
        for(int l = 0 ; l < width ; l++){
            for(int ll = 0 ; ll < high ; ll++){
                img (l,ll, 0 , 0) = temp.at<cv::Vec4b>(ll,l)[0]; 
                img (l,ll, 0 , 1) = temp.at<cv::Vec4b>(ll,l)[1]; 
                img (l,ll, 0 , 2) = temp.at<cv::Vec4b>(ll,l)[2];
                img (l,ll, 0 , 3) = temp.at<cv::Vec4b>(ll,l)[3]; // aplha chanell
            }
        }

It compile well, but in runtime there is assertion failed with mat.hpp in line 537. If i commented loops everything works without result ok.

Please Do Yiou have some ideas, please ?

Best Regards, Szymsztein

Edit:

Current code works, but rewriting from cimg to opencv not... :

CImg<unsigned char> finalimg2(x,a);
    ////////////////////////////////////////
    ////////////////////////////
    finalimg.append(finalimg2,'y',0);

    Mat tmp = Mat(finalimg.width(), finalimg.height(), DataType<cv::Vec4w>::type);
    // Rewrite from CImg to opencvi kno w
        for(int l = 0 ; l < finalimg.width() ; l++){
            for(int ll = 0 ; ll < finalimg.height() ; ll++){
                if( sizeof(finalimg(l,ll,0,0)) != 8)
                    cout << "(" << l << ", " << ll << ") size = " << sizeof(finalimg(l,ll,0,0)) << " ";
                tmp.at<cv::Vec4w>(ll,l)[0] = finalimg(l,ll, 0 , 0);
                tmp.at<cv::Vec4w>(ll,l)[1] = finalimg(l,ll, 0 , 1); 
                tmp.at<cv::Vec4w>(ll,l)[2] = finalimg(l,ll, 0 , 2); 
                tmp.at<cv::Vec4w>(ll,l)[3] = finalimg(l,ll, 0 , 3); 
            }
        }

        char resultName[15];
        //sprintf(resultName, "result%d.png", p);
        imwrite("result.png", tmp);

When i use Ve4w, these images which had type == 26, works well and are on output message, when i use vec4b, on output images there are only these images awhich had type ==26...