Ask Your Question

thistle's profile - activity

2014-06-27 04:03:44 -0600 asked a question From cv::Mat to UIImage strange problem

I am using the code you provided to turn a cv::Mat into a UIImage. The code follows:

- (void) setImage:(cv::Mat ) cvMat {
   NSData *data = [NSData dataWithBytes:cvMat.data length:cvMat.elemSize()*cvMat.total()];
   CGColorSpaceRef colorSpace;
   double min=0, max=0;
   cv::minMaxLoc(cvMat, &min, &max);
   NSLog(@"Min %f Max %f", min, max);

  if (cvMat.elemSize() == 1) {
       NSLog(@"Received gray-level image");
       NSLog(@"W H: %d %d", cvMat.cols, cvMat.rows);
      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], // cvMat.cols, //cvMat.step[0],                            //bytesPerRow
                                    colorSpace,                                 //colorspace
                                    kCGImageAlphaNone|kCGBitmapByteOrderDefault,// bitmap info
                                    provider,                                   //CGDataProviderRef
                                    NULL,                                       //decode
                                    false,                                      //should interpolate
                                    kCGRenderingIntentDefault                   //intent
                                    );
         ...

This code does not work in my program. The CGImageRef imageRef = CGImageCreate(cvMat.cols, ... fails.

After a little bit of debugging, I noticed that after the following instruction:

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

all the input cvMat fields are set to NULL. See screenshots before & after.

What am I doing wrong?

The instruction is not executed in the main thread. I will try and move it into the main thread and see what happens, but its side effects should be documented somewhere...

BEFORE:

BEFORE CGDataProvider

AFTER:

AFTER CGDataProvider

2014-05-23 13:09:28 -0600 asked a question Problems with 2.4.9 and OS X 10.8.5

I am still using OpenCV 2.4.4 because I have never been able to compile the subsequent releases on my OS X machines.

Since I am sick at home, today I decided to try again and upgrade OpenCV to the latest 2.4.9 version. As with previous versions, the compilation failed.

The problem is related to the CUDA compilation. During the CMake processing, I get this (for me) obscure error message.

- CUDA NVCC target flags: -gencode;arch=compute_11,code=sm_11;-gencode;arch=compute_12,code=sm_12;-gencode;arch=compute_13,code=sm_13;-gencode;arch=compute_20,code=sm_20;-gencode;arch=compute_20,code=sm_21;-gencode;arch=compute_30,code=sm_30;-gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_30,code=compute_30
  CMake Warning (dev) at cmake/OpenCVDetectCUDA.cmake:245 (link_directories):
  This command specifies the relative path

     -Wl,/usr/local/cuda

  as a link directory.

 Policy CMP0015 is not set: link_directories() treats paths relative to the
 source dir.  Run "cmake --help-policy CMP0015" for policy details.  Use the
 cmake_policy command to set the policy and suppress this warning.

Call Stack (most recent call first):
cmake/OpenCVFindLibsPerf.cmake:24 (include)
CMakeLists.txt:468 (include)

This warning is for project developers.  Use -Wno-dev to suppress it.

May be that's why the compilation fails? Indeed, it fails exactly when linking GPU-related object files.

Cheers

2014-03-12 07:30:03 -0600 asked a question Compiling 2.4.8 without shared libs

Is it still possible to compile OpenCV as static libraries?

I am trying to compile OpenCV 2.4.8 (Linux distribution) without producing dynamic libraries.

The command I use is the following one:

 cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/.../user/work/libs/opencv -D BUILD_SHARED_LIBS=off ..

When I compile, I got the following error:

 [19%] Generating precomp.hpp.gch/opencv_core_RELEASE.gch
 /usr/lib/../lib64/crt1.o: In function `_start':
 /usr/src/packages/BUILD/glibc-2.11.1/csu/../sysdeps/x86_64/elf/start.S:109: undefined reference to `main'
 collect2: error: ld returned 1 exit status
 make[2]: *** [modules/core/precomp.hpp.gch/opencv_core_RELEASE.gch] Error 1
 make[1]: *** [modules/core/CMakeFiles/pch_Generate_opencv_core.dir/all] Error 2

which is clearly to related to static/dynamic linking.

Is there anyone who can tell me what I am doing wrong?

cheers

2014-01-26 01:34:54 -0600 received badge  Editor (source)
2014-01-26 01:33:18 -0600 asked a question Cannot compile 2.4.8 on OS X 10.8.5

I have been using OpenCV for several years and I have never had problems in compiling the sources on my macs, but I am not able to compile the latest sources (2.4.8) on my OS X 10.8.5 machine.

I am building OpenCV using CMake with the flag -DBUILD_SHARED_LIBS=OFF (followed by make), as suggested on the page explaining how to generate the binaries for using the Java interface. The compiler is i686-apple-darwin11-llvm-gcc-4.2. When I run CMake I get only this error:

-- Found PythonInterp: /opt/local/bin/python (found suitable version "3.3", minimum required is "2.0") 
-- Could NOT find PythonLibs: Found unsuitable version "2.7.2", but required is exact version "3.3" (found     PYTHON_LIBRARY-NOTFOUND)
 File "<string>", line 1
 from distutils.sysconfig import *; print get_python_lib()
                                                      ^
SyntaxError: invalid syntax
   File "<string>", line 1
import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print   numpy.distutils.misc_util.get_numpy_include_dirs()[0]
                                                                                  ^
SyntaxError: invalid syntax

I installed the latest python for OS X and used the variable PYTHON_LIBRARIES (pointing to the 3.3 dylib) but the error remains.

First, I had a problem related to libavcodec, but a quick search suggested to remove ffmpeg from my computer. After the removal the error went away.

Now, I have the following message errors,

Scanning dependencies of target opencv_test_contrib
[ 85%] Building CXX object modules/contrib/CMakeFiles/opencv_test_contrib.dir/test/test_main.cpp.o
Linking CXX executable ../../bin/opencv_test_superres
Linking CXX executable ../../bin/opencv_test_contrib
[ 85%] Built target opencv_test_contrib
[ 85%] Generating core+CvException-jdoc.java, [and many others …]
make[2]: *** [modules/java/core+CvException-jdoc.java] Error 1
make[1]: *** [modules/java/CMakeFiles/opencv_java.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 85%] Built target opencv_test_superres
make: *** [all] Error 2

I cannot find any information on this particular problem. Is there anyone who can help me?