Ask Your Question

rogeralms's profile - activity

2014-09-18 21:14:07 -0600 commented question cv.h not found need help with makefile

The answer is not necessarily in the makefile. I replaced the headers with

include <opencv2/core/core.hpp>

include <opencv2/highgui/highgui.hpp>

I also removed cout and using namespace std; with printf.

I had started using the older version of OpenCV when I began to code and switched to CV2 accidentally leaving the older headers.My original makefile with just LIBS = $(LIBPATH)/libopencv_core.so $(LIBPATH)/libopencv_highgui.so works just fine.

2014-09-18 07:14:44 -0600 asked a question cv.h not found need help with makefile

I want to thank everyone for the help they have given me so far.

I am a Windows person and haven't used a makefile in over 20 years so I really don't know what I'm doing.

I have developed my program in Visual Studio 2012 and it works fine but I must move it to a UNIX server for the class I'm taking. I used the sample makefile from class but when I ran it, I got the message cv.h not found.

After looking over my project in Visual Studio, I determined that I needed to include the following libraries: opencv_core249d.lib opencv_imgproc249d.lib opencv_highgui249d.lib opencv_ml249d.lib opencv_video249d.lib opencv_features2d249d.lib opencv_calib3d249d.lib

without the 249d. I found these libraries in the given directory on the UNIX server as .SO files.

I am having trouble with the LIBS statement:

CC = g++ CFLAGS = -g TARGET = objects OBJS = objects.o LIBPATH = /usr/lib64 LIBS = $(LIBPATH)/libopencv_core.so $(LIBPATH)/libopencv_highgui.so $(LIBPATH)/libopencv_imgproc.so $(LIBPATH)/libopencv_ml.so $(LIBPATH)/libopencv_video.so $(LIBPATH)/libopencv_features2d.so $(LIBPATH)/libopencv_calib3d.so

$(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LIBS)

.SUFFIXES: .cpp .o

.c.o: $(CC) -c $(CFLAGS) $<

.PHONY: clean

clean: /bin/rm -f core *.o $(TARGET)

When I ran make, the message was: * missing separator. Stop.

Could someone point me to a good tutorial on makefiles for OpenCV, or tell me what I'm doing wrong with this makefile, or perhaps both?

Thank you.

2014-09-14 10:03:09 -0600 commented question Heap error OpenCV 2.4.9

Thank you so much! I copied that statement from the previous one and forgot to change the array boundaries.

2014-09-14 08:20:19 -0600 asked a question Heap error OpenCV 2.4.9

Hi, I am a little rusty in C++. I am trying to display a black background gray-scale image with a square and rectangle placed randomly within the image. The square and rectangle have a white center and progressively get darker towards the edges. Displaying the square worked fine but when I added the rectangle, I am now getting a heap error when I press enter to close the display window.

Here is what is diplayed when the system breakpoint occurs:

extern "C" _CRTIMP int __cdecl _CrtIsValidHeapPointer( const void * pUserData ) { if (!pUserData) return FALSE;

    if (!_CrtIsValidPointer(pHdr(pUserData),

sizeof(_CrtMemBlockHeader), FALSE)) return FALSE;

    return HeapValidate( _crtheap, 0, pHdr(pUserData) ); }

My code is below. Can someone point me in the right direction to correct this error?

Thank you.

include opencv\cv.h
include opencv\highgui.h
include cmath
include ctime

using namespace cv;
using namespace std;

int main()
{
    int chanl;                              // number of channels
    int imgdepth;                               // image depth
    float xdiff;            // difference between current pixel and center of figure cols
    float ydiff;            // difference between current pixel and center of figure rows
    float totdiff;              // use 2-d distance formula sqrt of sum of squares
    float two = 2.0;
    float xsqr;                         // square of col difference
    float ysqr;                         // square of row difference
    srand( time(0));                // needed to ensure true randomness for rand
    int xrand = rand()%480 - 50;                // random col position for figure
    int yrand = rand()%640 - 50;                // random row position for figure
    int ximg = xrand;
    int yimg = yrand;
    int minint = 255;                       // check for minimum intensity
    int maxint = 0;                         // check for max intensity  
    uchar* inp;                         // uchar* pointer for figure
    uchar* otp;                         // uchar* pointer for image

    Mat img = Mat::zeros(640,480, CV_8UC1);     // black background image
    Mat sqr = Mat::ones(100,100, CV_8UC1);      // white square 100x100 pixels
    Mat rct = Mat::ones(200,100, CV_8UC1);      // white rectangle 200x100 pixels
    Mat cir = Mat::zeros(70,70, CV_8UC1);   // black square to hold circle of radius 70 pixels

    // loop through white square where y is the row and x is the column
    // rows 0-99 and cols 0-99
    for( int y=0; y < 100; y++ ) 
    {
        inp= sqr.ptr<uchar>(y);             // pointer to current pixel in square
        for( int x=0; x < 100; x++ ) 
        {
            xdiff = float(x - 50);      // column difference from current pixel to center
            ydiff = float(y - 50);      // row difference from current pixel to center
            xsqr = pow(xdiff,two);              // square of column difference
            ysqr = pow(ydiff,two);              // square of row difference
            totdiff = sqrt( xsqr + ysqr);       // 2-d planar distance
            inp[x] = uchar(255 - int(totdiff)); 
                                                 // set center to white (ie totdiff = 0) and
                        // progressively get darker as you move from center
            if (inp[x] < minint)        // capture the minimum intensity of the square
            {
                minint = inp[x];
            }
            if (inp[x] > maxint)        // capture the maximum intensity of the square
            {
                maxint = inp[x];
            }
            if (yrand >= 0 && yrand < 640)      
// test row boundary in case square goes beyond edge of image
            {
                if (xrand >= 0 && xrand < 480)  
// test col boundary in case square goes beyond edge of image
                {
                    otp= img.ptr<uchar>(yrand); 
// if inside image, overlay intensity with value from square
                    otp ...
(more)
2014-09-07 16:44:28 -0600 received badge  Self-Learner (source)
2014-09-06 22:03:33 -0600 commented answer What is the best way to calculate the Weber ratio for an image?

Thanks, I will rewrite for the real assignment since it will probably be changed. The old O'Reilly book uses cv1 and the online documentation used both cv1 and cv2. At least I can now access my way through the image pixel by pixel. Many more interesting things to come. Thanks loads for your help!

2014-09-06 10:44:46 -0600 answered a question What is the best way to calculate the Weber ratio for an image?

Would someone look over the following code and screen capture to see if I am calculating the Weber ratio correctly? I was very confused at first mixing cv1 and cv2. Pound signs and brackets removed on include

include opencv\cv.h

include opencv\highgui.h

using namespace cv; using namespace std;

int main() { char infilestr[255]; // input file name

int imgtype;                            // image type

int chanl;                          // number of channels

int imgdepth;
Mat img;
int diff = 0;
float weber = 0;
int totpixels = 0;
float totweber = 0;

while (!img.data)
{
    cout << "Please enter the name of the image file you wish to open:" << endl;
    cin.getline(infilestr, 255, '\n');
    img = imread(infilestr);
    if (!img.data)                          // check for valid image
    {
        cout << "The image file you specified could not be loaded, try again." << endl;
    }
}                                           // end while

Mat::MSize dim = img.size;
Mat grayimg;
imgtype = img.type();
chanl = img.channels();
imgdepth = img.depth();

cout <<  "The image type is: " << imgtype << endl;
cout << "The image depth is: " << imgdepth << endl;
if (chanl == 3)
{
    cout << "The original image was in color. Channels = :" << chanl << endl;
    cvtColor( img, grayimg, CV_BGR2GRAY );
}
else
{
    grayimg = img;
}
Scalar meanval = mean(grayimg,noArray());

Mat Web(img);
int height = img.rows;
int width = img.cols * 3;
int step = img.step;
int h = grayimg.rows;
int w = grayimg.cols;

for( int y=0; y < h; y++ ) 
{
    uchar* inp= grayimg.ptr<uchar>(y);
    for( int x=0; x < w; x++ ) 
    {
        diff = abs(meanval(0) - inp[x]);
        weber = diff/meanval(0);
        totweber += weber;
        totpixels++;
    }
}

totweber = totweber / totpixels; 
cout << "The average intensity of the grayscale image is: " << meanval(0) << endl;
cout << "The average weber ratio for the grayscale image is: " << totweber << endl;
namedWindow("Example1", CV_WINDOW_NORMAL);
imshow("Example1", grayimg);
waitKey(0);
return 0;

} image description

2014-09-03 23:10:43 -0600 asked a question What is the best way to calculate the Weber ratio for an image?

I am new to openCV and am taking a class in digital image processing. I am working through prior years assignment in preparation for our upcoming assignment.

  1. Write a program to display information about an image. The information we are interested in is the dimensions of the image, its average gray scale intensity, its Weber ratio, and its format (gif/jpeg/tiff). If the input image is color, convert it to grayscale before computing the above attributes, and output a message that the input image is in color.

Is there a better way to calculate the Weber Ratio? I have used the following code so far to calculate the mean overall intensity, should I take absolute value |meanval - each point intensity| divided by meanval to get this ratio?:

CvSize dim = cvGetSize(image);
Mat img(image);
Mat grayimg;
imgtype = img.type();
chanl = img.channels();

cout <<  "The image type is: " << imgtype << endl;
if (chanl == 3)
{
    cout << "The original image was in color. Channels = :" << chanl << endl;
    cvtColor( img, grayimg, CV_BGR2GRAY );
}
else
{
    grayimg = img;
}
Scalar meanval = mean(grayimg,noArray());