resize function returns shifted image columns on OSX Mavericks 64bit opencv 2.4.7

asked 2013-12-10 23:55:44 -0600

I'm using OpenCV 2.4.7 on OSX Mavericks 64bit.

I installed OpenCV using mac ports

'sudo port install opencv'.

I pointed the search path headers and libraries (respectively) to



In the Build phases: I've added the following to the `Link Binary with Libraries' section:



Builds in Xcode 5 without issues.

I run into problem with the resize function of OpenCV. I tested a scenario where the dst image has the same width and height as the src image. So basically the dimensions were not altered and the returned image is as expected ....

image description

However when I double the width of the image, pixel columns are shifted (like a interlacing/ghosting effect)...

image description

My Objective-C function is as follow:

- (NSMutableArray*) resizeWithPixelData: (NSMutableArray*) pixelData withWidth: (int) width withHeight: (int) height withFactor: (float) resizeFactor withDirection: (NSString*) resizeDirection {

    cv::Mat image(height,width,CV_8UC1); //height, width ... no colours.
    //NSLog(@" %i %i",image.cols,image.rows);
    for (int i = 0; i < image.rows; i++) {
        for (int j = 0; j < image.cols; j++) {
            cv::Vec3b &intensity =<cv::Vec3b>(i, j);
            for(int k = 0; k < image.channels(); k++) {
                //uchar col = intensity.val[k];
                uint8_t value = [[pixelData objectAtIndex:i*width + j] intValue];;
                intensity.val[k] = (uchar) value;

    cv::Mat newimage;
    //NSLog(@"height %d width %d",height,resizeFactor*width);
    if ([resizeDirection isEqualToString:@"x"]){
        cv::resize(image, newimage, cv::Size((int)resizeFactor*width,(int)height),0,0,CV_INTER_CUBIC);

    NSLog(@" resize width width %i height %i ",image.cols,image.rows);
    NSLog(@" resize width width %i height %i ",newimage.cols,newimage.rows);

    NSMutableArray* resizedPixelData = [[NSMutableArray alloc] init];

    for (int i = 0; i < newimage.rows; i++) {
        for (int j = 0; j < newimage.cols; j++) {
            cv::Vec3b intensity =<cv::Vec3b>(i, j);
            for(int k = 0; k < newimage.channels(); k++) {
                uchar col = intensity.val[k];
                //NSLog(@" %i ",(uint8_t)col);
                [resizedPixelData addObject:[NSNumber numberWithInt:(uint8_t)col]];
    return resizedPixelData;

Much appreciated if anyone can point out a fix for this problem.

Is it the current version of opencv?

Is the call to the resize function incorrect?

Incompatibility with Xcode/OSX/Mavericks?

The above function is in a .mm file, (i.e. objective-C plus plus).



edit retag flag offensive close merge delete