Ask Your Question
0

Counting Pixels

asked 2013-07-09 17:52:02 -0600

Evil Potato gravatar image

I am trying to read each row's number of black pixel. So I set up the for loop, but I am getting an errors.

error C2064: term does not evaluate to a function taking 1 arguments error

What am I doing wrong?

PS I'm sorry I'm using C instead of C++ because I only have the old edition book :(

#include <highgui.h>
#include <cv.h>

int main()
{
    int total,
        zero,
        width,
        black_pixel;

    IplImage* in = cvLoadImage("Wallet.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    IplImage* gsmooth = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);
    IplImage* erode = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);
    IplImage* Iat = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);
    IplImage* bpixel = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);

    cvSmooth(in, gsmooth, CV_GAUSSIAN, 3, 0, 0, 0);
    cvErode(gsmooth, erode, NULL, 2);
    cvThreshold(erode, Iat, 100, 255, CV_THRESH_BINARY);

    total = (Iat->height)*(Iat->width);

    zero = total - cvCountNonZero(Iat);

    printf("Total pixels: %d\nWhite pixels: %d\nBlack pixels: %d", total, cvCountNonZero(Iat), zero);

    for(int x = 0; x < Iat->width; x++)
    {
        black_pixel = (Iat->width) - cvCountNonZero(Iat->width(x));
        printf("%d", black_pixel);
    }

    cvNamedWindow("Original", 1);
    cvNamedWindow("Gaussian Smoothing", 1);
    cvNamedWindow("Erode", 1);
    cvNamedWindow("Adaptive Threshold", 1);

    cvShowImage("Original", in);
    cvShowImage("Gaussian Smoothing", gsmooth);
    cvShowImage("Erode", erode);
    cvShowImage("Adaptive Threshold", Iat);

    cvWaitKey(0);

    cvReleaseImage(&in);
    cvReleaseImage(&gsmooth);
    cvReleaseImage(&erode);
    cvReleaseImage(&Iat);

    cvDestroyWindow("Original");
    cvDestroyWindow("Gaussian Smoothing");
    cvDestroyWindow("Erode");
    cvDestroyWindow("Adaptive Threshold");
}
edit retag flag offensive close merge delete

Comments

The new openCV starter book as well as the documentation contain the new C++ style API. Try switching, it will make your life quiet nicer using openCV.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-10 04:14:07 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-07-10 04:04:29 -0600

Guanta gravatar image

I am not familiar with the C-Api, but I doubt that with Iat->width(x) you will get a row, use cvGetRow(), see http://docs.opencv.org/modules/core/doc/old_basic_structures.html#CvMat%20cvGetRow(const%20CvArr%20arr,%20CvMat*%20submat,%20int%20row)). Furthermore, your loop-ending Iat->width seems wrong, since I guess you want to iterate over all rows, i.e. you probably need Iat->height.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-07-09 17:52:02 -0600

Seen: 591 times

Last updated: Jul 10 '13