Ask Your Question

Faiton's profile - activity

2015-03-06 04:05:45 -0600 received badge  Notable Question (source)
2014-03-20 14:48:10 -0600 received badge  Popular Question (source)
2013-03-20 15:47:11 -0600 asked a question how to convert image to gray color with OpenCV

I'm a new in OpenCV. I have some issues with image converting. I create a new project. It has 2 more files Wrapper.h/mm and UIImage+OpenCV.h/.mm. The following code is here:

//UIImage+OpenCV.h
#import <UIKit/UIKit.h>

@interface UIImage (OpenCV)

//cv::Mat to UIImage
+ (UIImage *)imageWithCVMat:(const cv::Mat&)cvMat;
+ (UIImage *)imageWithCVMat:(const cv::Mat&)cvMat
                orientation:(UIImageOrientation)orientation;

- (id)initWithCVMat:(const cv::Mat&)cvMat
        orientation:(UIImageOrientation)orientation;

//UIImage to cv::Mat
- (cv::Mat)CVMat;
- (cv::Mat)CVMat3;  // no alpha channel
- (cv::Mat)CVGrayscaleMat;

@end


//UIImage+OpenCV.mm
#import "UIImage+OpenCV.h"

@implementation UIImage (OpenCV)

-(cv::Mat)CVMat
{
    CGColorSpaceRef colorSpace = CGImageGetColorSpace(self.CGImage);
    CGFloat cols = self.size.width;
    CGFloat rows = self.size.height;

    cv::Mat cvMat(rows, cols, CV_8UC4); // 8 bits per component, 4 channels

    CGContextRef contextRef = CGBitmapContextCreate(cvMat.data,                 // Pointer to  data
                                                    cols,                       // Width of bitmap
                                                    rows,                       // Height of bitmap
                                                    8,                          // Bits per component
                                                    cvMat.step[0],              // Bytes per row
                                                    colorSpace,                 // Colorspace
                                                    kCGImageAlphaNoneSkipLast |
                                                    kCGBitmapByteOrderDefault); // Bitmap info flags

    CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), self.CGImage);
    CGContextRelease(contextRef);



    return cvMat;
}

- (cv::Mat)CVMat3
{
    cv::Mat result = [self CVMat];
    cv::cvtColor(result , result , CV_RGBA2RGB);
    return result;

}

-(cv::Mat)CVGrayscaleMat
{
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
    CGFloat cols = self.size.width;
    CGFloat rows = self.size.height;

    cv::Mat cvMat(rows, cols, CV_8UC1); // 8 bits per component, 1 channels

    CGContextRef contextRef = CGBitmapContextCreate(cvMat.data,                 // Pointer to data
                                                    cols,                       // Width of bitmap
                                                    rows,                       // Height of bitmap
                                                    8,                          // Bits per component
                                                    cvMat.step[0],              // Bytes per row
                                                    colorSpace,                 // Colorspace
                                                    kCGImageAlphaNone |
                                                    kCGBitmapByteOrderDefault); // Bitmap info flags

    CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), self.CGImage);
    CGContextRelease(contextRef);
    CGColorSpaceRelease(colorSpace);

    return cvMat;
}

+ (UIImage *)imageWithCVMat:(const cv::Mat&)cvMat
{
    return [[UIImage alloc] initWithCVMat:cvMat];
}

- (id)initWithCVMat:(const cv::Mat&)cvMat
{
    NSData *data = [NSData dataWithBytes:cvMat.data length:cvMat.elemSize() * cvMat.total()];
    CGColorSpaceRef colorSpace;

    if (cvMat.elemSize() == 1) {
        colorSpace = CGColorSpaceCreateDeviceGray();
    } else {
        colorSpace = CGColorSpaceCreateDeviceRGB();
    }

    CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);

    // Creating CGImage from cv::Mat
    CGImageRef imageRef = CGImageCreate(cvMat.cols,                                 //width
                                        cvMat.rows,                                 //height
                                        8,                                          //bits per component
                                        8 * cvMat.elemSize(),                       //bits per pixel
                                        cvMat.step[0],                              //bytesPerRow
                                        colorSpace,                                 //colorspace
                                        kCGImageAlphaNone|kCGBitmapByteOrderDefault,// bitmap info
                                        provider,                                   //CGDataProviderRef
                                        NULL,                                       //decode
                                        false,                                      //should interpolate
                                        kCGRenderingIntentDefault                   //intent
                                        );

    // Getting UIImage from CGImage
    self = [self initWithCGImage:imageRef];
    CGImageRelease(imageRef);
    CGDataProviderRelease(provider);
    CGColorSpaceRelease(colorSpace);

    return self;
}

@end

Above code I took here

//Wrapper.h
#import <Foundation/Foundation.h>

@interface CVWrapper : NSObject
+(UIImage*) returnPic: (UIImage*)image;
@end

//Wrapper.mm
#import "CVWrapper.h"
#import "UIImage+OpenCV.h"

@implementation CVWrapper

+(UIImage*)returnPic:(UIImage *)image
{
    UIImage *result = nil;
    if (image)
    {
        cv::Mat matImage = [image CVMat];
        cv::Mat greyMat;                      
        cv::cvtColor(matImage, greyMat, CV_RGBA2GRAY);  //It doesn't work
        result = [UIImage imageWithCVMat:greyMat];

    }

    return result;
}

@end

In ViewController I call the function that displays an image. I try to understand a basic concepts. How can i convert a picture in a grey color? Where i have to do it?

2013-02-17 10:38:40 -0600 received badge  Editor (source)
2013-02-17 10:37:32 -0600 asked a question can't make a framework opencv

I ask a several times how to create a framework correctly? Plz anybody knows I try to install opencv on macbook pro following this instruction i have problem when i build OpenCV framework. when i type

python opencv/ios/build_framework.py iOS

i got this problem:

CMake Error: Internal CMake error, TryCompile configure of cmake failed -- Looking for linux/videodev.h - not found -- Looking for linux/videodev2.h CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component): get_filename_component called with incorrect number of arguments Call Stack (most recent call first): CMakeLists.txt:3 (PROJECT)

CMake Error: Internal CMake error, TryCompile configure of cmake failed -- Looking for linux/videodev2.h - not found -- Looking for sys/videoio.h CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component): get_filename_component called with incorrect number of arguments Call Stack (most recent call first): CMakeLists.txt:3 (PROJECT)

CMake Error: Internal CMake error, TryCompile configure of cmake failed -- Looking for sys/videoio.h - not found -- Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version "2.0") -- Performing Test HAVE_OBJCXX_FOBJC_EXCEPTIONS CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCXXInformation.cmake:37 (get_filename_component): get_filename_component called with incorrect number of arguments Call Stack (most recent call first): CMakeLists.txt:3 (PROJECT)

CMake Error: Internal CMake error, TryCompile configure of cmake failed

-- Performing Test HAVE_OBJCXX_FOBJC_EXCEPTIONS - Failed -- General configuration for OpenCV 2.4.9 ===================================== -- Platform: -- Host: Darwin 11.4.2 i386 -- Target: iOS -- CMake: 2.8.10 -- CMake generator: Xcode -- CMake build tool: /opt/local/bin/cmakexbuild

-- Xcode: 4.3.3 -- C/C++: -- Built as dynamic libs?: NO -- C++ Compiler: CMAKE_CXX_COMPILER-NOTFOUND -- C++ flags (Release): -stdlib=libc++ -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG -O3 -fomit-frame-pointer -ffast-math -- C++ flags (Debug): -stdlib=libc++ -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden -- C Compiler: CMAKE_C_COMPILER-NOTFOUND -- C flags (Release): -- C flags (Debug): -- Linker flags (Release): -- Linker flags (Debug):

-- Precompiled headers: NO -- OpenCV modules: -- To be built: core imgproc flann highgui features2d calib3d ml video objdetect contrib legacy nonfree photo stitching videostab world -- Disabled: - -- Disabled by dependency: -

-- Unavailable: androidcamera gpu java ocl python ts -- GUI: -- Cocoa: YES

-- OpenGL support: NO -- Media I/O: -- ZLib: build (ver 1.2.7) -- JPEG: NO -- PNG: NO -- TIFF: NO -- JPEG 2000: NO

-- OpenEXR: NO -- Video I/O: -- AVFoundation: YES -- QuickTime: NO -- QTKit: YES

-- V4L/V4L2: NO/NO -- Other third-party libraries: -- Use OpenCL: NO -- Use Eigen: NO

-- Use Clp: NO -- Python:

-- Interpreter: NO -- Documentation: -- Build Documentation: NO -- Sphinx: NO

-- PdfLaTeX compiler: NO -- Tests and samples: -- Tests: NO -- Performance tests: NO

-- Examples: NO -- Install path: /usr/local/working_directory/ios/build/iPhoneSimulator-i386/install -- cvconfig.h is in: /usr/local/working_directory/ios/build/iPhoneSimulator-i386


-- Configuring incomplete, errors occurred! error: can't exec '/Developer/usr/bin/xcodebuild' (No such file or directory) error: can't exec '/Developer/usr/bin/xcodebuild' (No such file or directory) Traceback (most recent call last): File "opencv/ios/build_framework.py", line 128, in <module> build_framework(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "..")), os.path.abspath(sys.argv[1])) File "opencv ...

(more)
2013-02-17 09:44:21 -0600 answered a question problem with installation opencv

I got a directory ~/opencv2.framework/Version instead of framework. WHY ???? what is my problem?

2013-02-07 11:25:32 -0600 received badge  Scholar (source)
2013-02-07 07:11:02 -0600 commented answer problem with installation opencv

I did it : $ git checkout 2.3.4
and when i type "python .../build_framework.py <some dir> i got the same problem" Configuring incomplete, errors occurred!

2013-02-07 06:24:56 -0600 commented answer problem with installation opencv

If you solve it let me know plz. I'll do it for u too

2013-02-07 00:39:27 -0600 received badge  Student (source)
2013-02-01 08:24:13 -0600 asked a question problem with installation opencv

Hello ! I try to install opencv on macbook pro following this instruction i have problem when i build OpenCV framework. when i type

python opencv/ios/build_framework.py iOS

i got this problem:

CMake Error: Internal CMake error, TryCompile configure of cmake failed -- Looking for linux/videodev.h - not found -- Looking for linux/videodev2.h CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component): get_filename_component called with incorrect number of arguments Call Stack (most recent call first): CMakeLists.txt:3 (PROJECT)

CMake Error: Internal CMake error, TryCompile configure of cmake failed -- Looking for linux/videodev2.h - not found -- Looking for sys/videoio.h CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component): get_filename_component called with incorrect number of arguments Call Stack (most recent call first): CMakeLists.txt:3 (PROJECT)

CMake Error: Internal CMake error, TryCompile configure of cmake failed -- Looking for sys/videoio.h - not found -- Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version "2.0") -- Performing Test HAVE_OBJCXX_FOBJC_EXCEPTIONS CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCXXInformation.cmake:37 (get_filename_component): get_filename_component called with incorrect number of arguments Call Stack (most recent call first): CMakeLists.txt:3 (PROJECT)

CMake Error: Internal CMake error, TryCompile configure of cmake failed

-- Performing Test HAVE_OBJCXX_FOBJC_EXCEPTIONS - Failed

-- General configuration for OpenCV 2.4.9 =====================================

-- Platform: -- Host: Darwin 11.4.2 i386 -- Target: iOS -- CMake: 2.8.10 -- CMake generator: Xcode -- CMake build tool: /opt/local/bin/cmakexbuild

-- Xcode: 4.3.3

-- C/C++: -- Built as dynamic libs?: NO -- C++ Compiler: CMAKE_CXX_COMPILER-NOTFOUND -- C++ flags (Release): -stdlib=libc++ -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG -O3 -fomit-frame-pointer -ffast-math -- C++ flags (Debug): -stdlib=libc++ -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden
-- C Compiler: CMAKE_C_COMPILER-NOTFOUND -- C flags (Release):
-- C flags (Debug):
-- Linker flags (Release):
-- Linker flags (Debug):

-- Precompiled headers: NO

-- OpenCV modules: -- To be built: core imgproc flann highgui features2d calib3d ml video objdetect contrib legacy nonfree photo stitching videostab world -- Disabled: - -- Disabled by dependency: -

-- Unavailable: androidcamera gpu java ocl python ts

-- GUI: -- Cocoa: YES

-- OpenGL support: NO

-- Media I/O: -- ZLib: build (ver 1.2.7) -- JPEG: NO -- PNG: NO -- TIFF: NO -- JPEG 2000: NO

-- OpenEXR: NO

-- Video I/O: -- AVFoundation: YES -- QuickTime: NO -- QTKit: YES

-- V4L/V4L2: NO/NO

-- Other third-party libraries: -- Use OpenCL: NO -- Use Eigen: NO

-- Use Clp: NO

-- Python:

-- Interpreter: NO

-- Documentation: -- Build Documentation: NO -- Sphinx: NO

-- PdfLaTeX compiler: NO

-- Tests and samples: -- Tests: NO -- Performance tests: NO

-- Examples: NO

-- Install path: /usr/local/working_directory/ios/build/iPhoneSimulator-i386/install

-- cvconfig.h is in: /usr/local/working_directory/ios/build/iPhoneSimulator-i386

-- -----------------------------------------------------------------

-- Configuring incomplete, errors occurred! error: can't exec '/Developer/usr/bin/xcodebuild' (No such file or directory) error: can't exec '/Developer/usr/bin/xcodebuild' (No such file or directory) Traceback (most recent call last): File "opencv/ios/build_framework.py", line 128, in <module> build_framework(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "..")), os.path.abspath(sys.argv[1])) File "opencv/ios/build_framework.py", line 120, in build_framework put_framework_together(srcroot, dstroot) File "opencv/ios ... (more)