Ask Your Question

niranjan.kotha's profile - activity

2021-10-18 05:11:21 -0600 received badge  Notable Question (source)
2020-04-21 16:36:57 -0600 received badge  Popular Question (source)
2016-06-13 11:36:05 -0600 asked a question Does tracking mean nothing but linking optical flow vectors?

If I find optical flow between successive frames of a video and link all the optical flow vectors, does this mean I have implemented tracking? If yes is this the simple way of tracking?

2016-06-05 11:58:27 -0600 commented answer Error in imwrite code specified in the opencv api reference

Thank you so much for the help

2016-06-05 11:58:07 -0600 received badge  Scholar (source)
2016-06-05 11:58:06 -0600 received badge  Supporter (source)
2016-06-05 00:30:41 -0600 asked a question Error in imwrite code specified in the opencv api reference

I am very new to opencv and started using OPENCV 3.0 I have run code taken from imwrite in the OPENCV API reference documentation as it is from link text and got the following error:

error: ‘CV_IMWRITE_PNG_COMPRESSION’ was not declared in this scope
     compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);

and the code is as follows:

#include <vector>
#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

void createAlphaMat(Mat &mat)
{
    for (int i = 0; i < mat.rows; ++i) {
        for (int j = 0; j < mat.cols; ++j) {
            Vec4b& rgba = mat.at<Vec4b>(i, j);
            rgba[0] = UCHAR_MAX;
            rgba[1] = saturate_cast<uchar>((float (mat.cols - j)) / ((float)mat.cols) * UCHAR_MAX);
            rgba[2] = saturate_cast<uchar>((float (mat.rows - i)) / ((float)mat.rows) * UCHAR_MAX);
            rgba[3] = saturate_cast<uchar>(0.5 * (rgba[1] + rgba[2]));
        }
    }
}

int main(int argv, char **argc)
{
    // Create mat with alpha channel
    Mat mat(480, 640, CV_8UC4);
    createAlphaMat(mat);

    vector<int> compression_params;
    compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
    compression_params.push_back(9);

    try {
        imwrite("alpha.png", mat, compression_params);
    }
    catch (runtime_error& ex) {
        fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
        return 1;
    }

    fprintf(stdout, "Saved PNG file with alpha data.\n");
    return 0;
}

Can someone help me in debugging this?