Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

histogram opencv c++ vs python

I'm converting histogram function which is written in c++ into python.

uchar val =img.at<uchar>(i,j);
hist.at<float>(lookup[val]) += 1;

I understood the first line "val = img[i,j] but what does the second line mean. is it talking about the lookup table? How should I do the conversion in python?

Thankyou

histogram opencv c++ vs python

I'm converting histogram function which is written in c++ into python.

uchar val =img.at<uchar>(i,j);
hist.at<float>(lookup[val]) += 1;

I understood the first line "val = img[i,j] img[i,j] but what does the second line mean. is it talking about the lookup table? How should I do the conversion in python?

Thankyou Thankyou

histogram opencv c++ vs python

I'm converting histogram function which is written in c++ into python.

    Mat  Detection:: histogram(Mat img,bool vis)
{
    int bins = 59;             // number of bins 256 -1 to ignore the last patterns (background pattern)

    Mat hist;       // histogram arrays
    // Initalize histogram array
    hist = Mat::zeros(bins, 1, CV_32FC1);
    for (int i = 0; i < img.rows; i++)
    {
        for (int j = 0; j < img.cols; j++)
        {
                uchar val =img.at<uchar>(i,j);
 hist.at<float>(lookup[val]) += 1;
        }
    }

    return hist;
}

I understood the first line "val = img[i,j] but what does the second line mean. is it talking about the lookup table? How should I do the conversion in python?

Thankyou

histogram opencv c++ vs python

I'm converting histogram function which is written in c++ into python.

    Mat  Detection:: histogram(Mat img,bool vis)
{
    int bins = 59;             // number of bins 256 -1 to ignore the last patterns (background pattern)

    Mat hist;       // histogram arrays
    // Initalize histogram array
    hist = Mat::zeros(bins, 1, CV_32FC1);
    for (int i = 0; i < img.rows; i++)
    {
        for (int j = 0; j < img.cols; j++)
        {
                uchar val =img.at<uchar>(i,j);
                hist.at<float>(lookup[val]) += 1;
1;   #on this line I'm facing the problem(is it talking about the lookup table? )
        }
    }

    return hist;
}

I understood the first line "val = img[i,j] but what does the second line mean. is it talking about the lookup table? How should I do the conversion in python?

Thankyou

histogram opencv c++ vs python

I'm converting histogram function which is written in c++ into python.

    Mat  Detection:: histogram(Mat img,bool vis)
{
    int bins = 59;             // number of bins 256 -1 to ignore the last patterns (background pattern)

    Mat hist;       // histogram arrays
    // Initalize histogram array
    hist = Mat::zeros(bins, 1, CV_32FC1);
    for (int i = 0; i < img.rows; i++)
    {
        for (int j = 0; j < img.cols; j++)
        {
                uchar val =img.at<uchar>(i,j);
                hist.at<float>(lookup[val]) += 1;   #on this line I'm facing the problem(is it talking about the lookup table? )
        }
    }

    return hist;
}

How should I do the conversion in python?python of this part [hist.at<float>(lookup[val]) += 1]?

Thankyou

histogram opencv c++ vs python

I'm converting histogram function which is written in c++ into python.

    Mat  Detection:: histogram(Mat img,bool vis)
{
    int bins = 59;             // number of bins 256 -1 to ignore the last patterns (background pattern)

    Mat hist;       // histogram arrays
    // Initalize histogram array
    hist = Mat::zeros(bins, 1, CV_32FC1);
    for (int i = 0; i < img.rows; i++)
    {
        for (int j = 0; j < img.cols; j++)
        {
                uchar val =img.at<uchar>(i,j);
                hist.at<float>(lookup[val]) += 1;   #on this line I'm facing the problem(is it talking about the lookup table? )
        }
    }

    return hist;
}

How should I do the conversion in python of this part [hist.at<float>(lookup[val]) += 1]?

Thankyou

histogram opencv c++ vs python

I'm converting histogram function which is written in c++ into python.

    Mat  Detection:: histogram(Mat img,bool vis)
{
    int bins = 59;             // number of bins 256 -1 to ignore the last patterns (background pattern)

    Mat hist;       // histogram arrays
    // Initalize histogram array
    hist = Mat::zeros(bins, 1, CV_32FC1);
    for (int i = 0; i < img.rows; i++)
    {
        for (int j = 0; j < img.cols; j++)
        {
                uchar val =img.at<uchar>(i,j);
                hist.at<float>(lookup[val]) += 1;   #on this line I'm facing the problem(is it talking about the lookup table? )
        }
    }

    return hist;
}

python conversion

def historgram(image):
    #cv2.historgram()
    bins = 59
    row,col,channels = image.shape

    hist = np.zeros((bins, 1), dtype = 'float32')    
    i = 0 
    j =0 
    while i < row:
        while j < col:
            val = image[i,j]
           ""
                      ""

            j = j+1
        i = 1+i
    return hist

How should I do the conversion in python of this part [hist.at<float>(lookup[val]) += 1]?

Thankyou