Coder Social home page Coder Social logo

kylemcdonald / ofxcv Goto Github PK

View Code? Open in Web Editor NEW
655.0 63.0 276.0 3.39 MB

Alternative approach to interfacing with OpenCv from openFrameworks.

License: Other

C++ 96.53% GLSL 0.30% C 0.67% Python 1.13% Makefile 1.37%
openframeworks addon opencv wrapper computer-vision

ofxcv's Introduction

Introduction

ofxCv represents an alternative approach to wrapping OpenCV for openFrameworks.

Installation

First, pick the branch that matches your version of openFrameworks:

Either clone out the source code using git:

> cd openFrameworks/addons/
> git clone https://github.com/kylemcdonald/ofxCv.git

Or download the source from GitHub here, unzip the folder, rename it from ofxCv-master to ofxCv and place it in your openFrameworks/addons folder.

To run the examples, import them into the project generator, create a new project, and open the project file in your IDE.

Goals

ofxCv has a few goals driving its development.

Wrap complex things in a helpful way

Sometimes this means: providing wrapper functions that require fewer arguments than the real CV functions, providing a smart interface that handles dynamic memory allocation to make things faster for you, or providing in place and out of place alternatives.

Present the power of OpenCv clearly

This means naming things in an intuitive way, and, more importantly, providing classes that have methods that transform the data represented by that class. It also means providing demos of CV functions, and generally being more useful than ofxOpenCv.

Interoperability of openFrameworks and OpenCv

Making it easy to work directly with CV by providing lightweight conversion functions, and providing wrappers for CV functions that do the conversions for you.

Elegant internal OpenCv code

Provide clean implementations of all functions in order to provide a stepping stone to direct OpenCV use. This means using function names and variable names that follow the OpenCV documentation, and spending the time to learn proper CV usage so I can explain it clearly to others through code. Sometimes there will be heavy templating in order to make OF interoperable with OpenCV, but this should be avoided in favor of using straight OpenCV as often as possible.

Usage

Sometimes this readme will fall out of date. Please refer to the examples as the primary reference in that case.

Project setup

Using ofxCv requires:

  • ofxCv/libs/ofxCv/include/ Which contains all the ofxCv headers.
  • ofxCv/libs/ofxCv/src/ Which contains all the ofxCv source.
  • ofxCv/src/ Which ties together all of ofxCv into a single include.
  • opencv/include/ The OpenCv headers, located in addons/ofxOpenCv/
  • opencv/lib/ The precompiled static OpenCv libraries, located in addons/ofxOpenCv/

Your linker will also need to know where the OpenCv headers are. In XCode this means modifying one line in Project.xconfig:

HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS) "../../../addons/ofxOpenCv/libs/opencv/include/" "../../../addons/ofxCv/libs/ofxCv/include/"

Alternatively, I recommend using OFXCodeMenu to add ofxCv to your project.

Including ofxCv

Inside your ofApp.h you will need one include:

#include "ofxCv.h"

OpenCv uses the cv namespace, and ofxCv uses the ofxCv namespace. You can automatically import them by writing this in your .cpp files:

using namespace cv;
using namespace ofxCv;

If you look inside the ofxCv source, you'll find lots of cases of ofxCv:: and cv::. In some rare cases, you'll need to write cv:: in your code. For example, on OSX Rect and Point are defined by OpenCv, but also MacTypes.h. So if you're using an OpenCv Rect or Point you'll need to say so explicitly with cv::Rect or cv::Point to disambiguate.

ofxCv takes advantage of namespaces by using overloaded function names. This means that the ofxCv wrapper for cv::Canny() is also called ofxCv::Canny(). If you write simply Canny(), the correct function will be chosen based on the arguments you pass.

Working with ofxCv

Unlike ofxOpenCv, ofxCv encourages you to use either native openFrameworks types or native OpenCv types, rather than introducing a third type like ofxCvImage. To work with OF and OpenCv types in a fluid way, ofxCv includes the toCv() and toOf() functions. They provide the ability to convert openFrameworks data to OpenCv data and vice versa. For large data, like images, this is done by wrapping the data rather than copying it. For small data, like vectors, this is done by copying the data.

The rest of ofxCv is mostly helper functions (for example, threshold()) and wrapper classes (for example, Calibration).

toCv() and copy()

toCv() is used to convert openFrameworks data to OpenCv data. For example:

ofImage img;
img.load("image.png");
Mat imgMat = toCv(img);

This creates a wrapper for img called imgMat. To create a deep copy, use clone():

Mat imgMatClone = toCv(img).clone();

Or copy(), which works with any type supported by toCv():

Mat imgCopy;
copy(img, imgCopy);

toCv() is similar to ofxOpenCv's ofxCvImage::getCvImage() method, which returns an IplImage*. The biggest difference is that you can't always use toCv() "in place" when calling OpenCv code directly. In other words, you can always write this:

Mat imgMat = toCv(img);
cv::someFunction(imgMat, ...);

But you should avoid using toCv() like this:

cv::someFunction(toCv(img), ...);

Because there are cases where in place usage will cause a compile error. More specifically, calling toCv() in place will fail if the function requires a non-const reference for that parameter.

imitate()

imitate() is primarily used internally by ofxCv. When doing CV, you regularly want to allocate multiple buffers of similar dimensions and channels. imitate() follows a kind of prototype pattern, where you pass a prototype image original and the image to be allocated mirror to imitate(mirror, original). imitate() has two big advantages:

  • It works with Mat, ofImage, ofPixels, ofVideoGrabber, and anything else that extends ofBaseHasPixels.
  • It will only reallocate memory if necessary. This means it can be used liberally.

If you are writing a function that returns data, the ofxCv style is to call imitate() on the data to be returned from inside the function, allocating it as necessary.

drawMat() vs. toOf()

Sometimes you want to draw a Mat to the screen directly, as quickly and easily as possible, and drawMat() will do this for you. drawMat() is not the most optimal way of drawing images to the screen, because it creates a texture every time it draws. If you want to draw things efficiently, you should allocate a texture using ofImage img; once and draw it using img.draw().

  1. Either use Mat mat = toCv(img); to treat the ofImage as a Mat, modify the mat, then img.update() to upload the modified pixels to the GPU.
  2. Alternatively; call toOf(mat, img) each time after modifying the Mat. This will only reallocate the texture if necessary, e.g. when the size has changed.

Working with OpenCv 2

OpenCv 2 is an incredibly well designed API, and ofxCv encourages you to use it directly. Here are some hints on using OpenCv.

OpenCv Types

OpenCv 2 uses the Mat class in place of the old IplImage. Memory allocation, copying, and deallocation are all handled automatically. operator= is a shallow, reference-counted copy. A Mat contains a collection of Scalar objects. A Scalar contains a collection of basic types (unsigned char, bool, double, etc.). Scalar is a short vector for representing color or other multidimensional information. The hierarchy is: Mat contains Scalar, Scalar contains basic types.

Different functions accept Mat in different ways:

  • Mat will create a lightweight copy of the underlying data. It's easy to write, and it allows you to use toCv() "in-place" when passing arguments to the function.
  • Mat& allows the function to modify the header passed in. This means the function can allocate if necessary.
  • const Mat& means that the function isn't going to modify the underlying data. This should be used instead of Mat when possible. It also allows "in-place" toCv() usage.

Mat creation

If you're working with Mat directly, it's important to remember that OpenCv talks about rows and cols rather than width and height. This means that the arguments are "backwards" when they appear in the Mat constructor. Here's an example of creating a Mat wrapper for some grayscale unsigned char* pixels for which we know the width and height:

Mat mat = Mat(height, width, CV_8UC1, pixels, 0);

Mat operations

Basic mathematical operations on Mat objects of the same size and type can be accomplished with matrix expressions. Matrix expressions are a collection of overloaded operators that accept Mat, Scalar, and basic types. A normal mathematical operation might look like:

float x, a, b;
...
x = (a + b) * 10;

A matrix operation looks similar:

Mat x, a, b;
...
x = (a + b) * 10;

This will add every element of a and b, then multiply the results by 10, and finally assign the result to x.

Available matrix expressions include mathematical operators +, -, / (per element division), * (matrix multiplication), .mul() (per-element multiplication). As well as comparison operators !=, ==, <, >, >=, <= (useful for thresholding). Binary operators &, |, ^, ~. And a few others like abs(), min(), and max(). For the complete listing see the OpenCv documention or mat.hpp.

Code Style

ofxCv tries to have a consistent code style. It's most similar to the K&R variant used for Java, and the indentation is primarily determined by XCode's auto-indent feature.

Multiline comments are used for anything beyond two lines.

Case statements have a default: fall-through with the last case.

When two or three similar variables are initialized, commas are used instead of multiple lines. For example Mat srcMat = toCv(src), dstMat = toCv(dst);. This style was inherited from reading Jason Saragih's FaceTracker.


ofxCv was developed with support from Yamaguchi Center for Arts and Media.

ofxcv's People

Contributors

armadillu avatar arturoc avatar avilleret avatar bakercp avatar companje avatar cyrildiagne avatar danoli3 avatar elliotwoods avatar fieldofview avatar galsasson avatar golanlevin avatar halfdanj avatar hamoid avatar jeffcrouse avatar kylemcdonald avatar micuat avatar ngbrown avatar nkint avatar noio avatar noisecapella avatar obviousjim avatar orgicus avatar prisonerjohn avatar roymacdonald avatar samatt avatar seem-less avatar totalgee avatar valillon avatar vanderlin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ofxcv's Issues

wrapThree functions have ups and downs

the imitate(y, x);\ line in the wrapThree macro is helpful when y isn't sized up yet. but if you have something that can't be imitate()'d because it's a videograbber or something, what do you do?

how often does it actually make sense for wrapThree to imitate, anyway?

Tracker labels get very large

it would take an extreme situation to actually break because of this, so i think it's better to ignore this problem until it has practical consequences.

if you're getting 30 new labels per second for 4 years, then the labels will loop back around to 0. but i think this behavior is probably fine given the complexity of implementing some kind of unused-labels-pool.

unresolved externals in VC++ 2010

ofxFaceTracker.obj : error LNK2019: unresolved external symbol "public: void __thiscall FACETRACKER::Tracker::Load(char const *)" (?Load@Tracker@FACETRACKER@@QAEXPBD@Z) referenced in function "public: void __thiscall ofxFaceTracker::setup(void)" (?setup@ofxFaceTracker@@QAEXXZ)
2>ofxFaceTracker.obj : error LNK2019: unresolved external symbol "public: int __thiscall FACETRACKER::Tracker::Track(class cv::Mat,class std::vector<int,class std::allocator > &,int,int,double,double,bool)" (?Track@Tracker@FACETRACKER@@QAEHVMat@cv@@aav?$vector@HV?$allocator@H@std@@@std@@HHNN_N@Z) referenced in function "public: bool __thiscall ofxFaceTracker::update(class cv::Mat)" (?update@ofxFaceTracker@@QAE_NVMat@cv@@@z)
2>bin\allAddonsExample_debug.exe : fatal error LNK1120: 2 unresolved externals

I can solve it under vc++ 2010

Xcode w/ LLVM - Call to function 'toCv' in Utilities.h fails

Using Xcode 4.3.2 and OF 007 the following error occurs when compiling with ofxCv (current master).

"Call to function 'toCv' that is neither visible in the template definition nor found by argument-dependent lookup"

The source of the issue: Line 134 of Utilities.h

// cross-toolkit, cross-bitdepth copying
    template <class S, class D>
    void copy(S& src, D& dst, int dstDepth) {
        imitate(dst, src, getCvImageType(getChannels(src), dstDepth));
        Mat srcMat = toCv(src), dstMat = toCv(dst);         // ------------------------ Error
        if(srcMat.type() == dstMat.type()) {
            srcMat.copyTo(dstMat);
        } else {
            double alpha = getMaxVal(dstMat) / getMaxVal(srcMat);
            srcMat.convertTo(dstMat, dstMat.depth(), alpha);
        }
    }

Two other programmers have the same issue with same configuration:
http://forum.openframeworks.cc/index.php?topic=10479.0

a version of the Tracker that uses a fixed number of objects

sometimes you know you will never have more than a certain number of objects, but you might have less (due to noisy inputs / bad data). in this case you don't want to continually be incrementing ids, but used a small fixed subset. consider the case of multitouch finger id tracking.

ofxCv on ios

Hello,

any ideas, why this addon crashes on ios? The ofxOpenCV addon examples run, but adapting e.g. example-background from this addon gives me this crash at runtime:
2011-09-21 21:40:44.099 opencvExample[2321:707] Creating OpenGL ES2 Renderer
2011-09-21 21:40:44.114 opencvExample[2321:707] Failed to load vertex shader
2011-09-21 21:40:44.118 opencvExample[2321:707] Failed to compile vertex shader
2011-09-21 21:40:44.121 opencvExample[2321:707] OpenGL ES2 failed
2011-09-21 21:40:44.147 opencvExample[2321:707] Creating OpenGL ES1 Renderer
2011-09-21 21:40:45.055 opencvExample[2321:707] layoutSubviews
OF: OF_LOG_WARNING: ofGLRenderer::draw(): texture is not allocated
OF: OF_LOG_WARNING: ofGLRenderer::draw(): texture is not allocated
[Switching to thread 12803]
2011-09-21 21:40:45.345 opencvExample[2321:707] Received memory warning. Level=1
OF: OF_LOG_WARNING: ofGLRenderer::draw(): texture is not allocated
OF: OF_LOG_WARNING: ofGLRenderer::draw(): texture is not allocated
OF: OF_LOG_WARNING: ofGLRenderer::draw(): texture is not allocated
OF: OF_LOG_WARNING: ofGLRenderer::draw(): texture is not allocated
OF: OF_LOG_WARNING: ofGLRenderer::draw(): texture is not allocated
OF: OF_LOG_WARNING: ofGLRenderer::draw(): texture is not allocated
OF: OF_LOG_WARNING: ofGLRenderer::draw(): texture is not allocated
OF: OF_LOG_WARNING: ofGLRenderer::draw(): texture is not allocated
OF: OF_LOG_WARNING: ofGLRenderer::draw(): texture is not allocated
OF: OF_LOG_WARNING: ofGLRenderer::draw(): texture is not allocated
OF: OF_LOG_WARNING: ofGLRenderer::draw(): texture is not allocated
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /Users/theo/Documents/CODE/__OPENFRAMEWORKS/gitOF/__BuildAllLibs/OpenCV-2.2.0-iPhone/modules/imgproc/src/color.cpp, line 2433
terminate called after throwing an instance of 'cv::Exception'
what(): /Users/theo/Documents/CODE/__OPENFRAMEWORKS/gitOF/__BuildAllLibs/OpenCV-2.2.0-iPhone/modules/imgproc/src/color.cpp:2433: error: (-215) scn == 3 || scn == 4 in function cvtColor

Tested on an current ipod touch. The debug messages (Creating OpenGL ES2 Renderer) are the same like in ofxOpenCV addon, the OF_LOG_WARNING only appear in ofxCv (Also the crash only happens here). The last (readable) entry in stacktrace, says, this happens in
cv::cvtColor(foreground, foregroundGray, CV_RGB2GRAY); //line 25 in RunningBackground.cpp

Regards,
sunatmidnight

smart thresholding should be a class

you regularly want to threshold using something like color, brightness, maybe HSB, or RGB. this is inside ContourFinder right now, but you may want to use it separately.

VS2010 Error Compiling Examples: unresolved externals

Sorry, I am new at this.
I have been trying for a few days to FaceTracker library and after finding some answers in different posts I realized the problem was with OpenCV. I am trying now to compile one of the examples of ofxCv but I keep getting linking error of unresolved externals.

In the linker > general > additional libraries I have this directory added:
......\addons\ofxOpenCv\libs\opencv\lib\vs2010
As additional dependencies I have this (debugger option)
opencv_calib3d231d.lib;opencv_contrib231d.lib;opencv_core231d.lib;opencv_features2d231d.lib;opencv_flann231d.lib;opencv_gpu231d.lib;opencv_haartraining_engined.lib;opencv_highgui231d.lib;opencv_imgproc231d.lib;opencv_legacy231d.lib;opencv_ml231d.lib;opencv_objdetect231d.lib;opencv_video231d.lib;zlibd.lib

I cannot figure out what am I missing. I would appreciate any hint.
Thanks!

P.S.
These are the unresolved symbols:

"int __cdecl cv::_interlockedExchangeAdd(int *,int)"(?_interlockedExchangeAdd@cv@@YAHPAHH@Z)
"double __cdecl cv::calibrateCamera ... " (?calibrate@Calibration@ofxCv@@QAE_NXZ)
"public: virtual class cv::GlBuffer __thiscall cv::_InputArray::getGlBuffer(void)const " (?getGlBuffer@_InputArray@cv@@UBE?AVGlBuffer@2@XZ)
"public: virtual class cv::GlTexture __thiscall cv::_InputArray::getGlTexture(void)const " (?getGlTexture@_InputArray@cv@@UBE?AVGlTexture@2@XZ)
"public: virtual class cv::gpu::GpuMat __thiscall cv::_InputArray::getGpuMat(void)const " (?getGpuMat@_InputArray@cv@@UBE?AVGpuMat@gpu@2@XZ)
"void __cdecl cv::calcOpticalFlowPyrLK(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_InputArray const &,class cv::_OutputArray const &,class cv::_OutputArray const &,class cv::_OutputArray const &,class cv::Size_<int>,int,class cv::TermCriteria,int,double)" (?calcOpticalFlowPyrLK@cv@@YAXABV_InputArray@1@00ABV_OutputArray@1@11V?$Size_@H@1@HVTermCriteria@1@HN@Z) referenced in function "protected: virtual void __thiscall ofxCv::FlowPyrLK::calcFlow(void)" (?calcFlow@FlowPyrLK@ofxCv@@MAEXXZ)
"int __cdecl cv::buildOpticalFlowPyramid(class cv::_InputArray const &,class cv::_OutputArray const &,class cv::Size_<int>,int,bool,int,int,bool)" (?buildOpticalFlowPyramid@cv@@YAHABV_InputArray@1@ABV_OutputArray@1@V?$Size_@H@1@H_NHH3@Z) referenced in function "protected: virtual void __thiscall ofxCv::FlowPyrLK::calcFlow(void)" (?calcFlow@FlowPyrLK@ofxCv@@MAEXXZ)
"class ofVec2f __cdecl closestPointOnRay(class ofVec2f const &,class ofVec2f const &,class ofVec2f const &)" (?closestPointOnRay@@YA?AVofVec2f@@ABV1@00@Z) referenced in function "public: void __thiscall Recognizer::update(class ofPolyline &)" (?update@Recognizer@@QAEXAAVofPolyline@@@Z)
"float __cdecl distanceToEllipse(class ofVec2f const &,class cv::RotatedRect const &)" (?distanceToEllipse@@YAMABVofVec2f@@ABVRotatedRect@cv@@@Z) referenced in function "public: void __thiscall Recognizer::update(class ofPolyline &)" (?update@Recognizer@@QAEXAAVofPolyline@@@Z)
"float __cdecl distanceToRay(class ofVec2f const &,class ofVec2f const &,class ofVec2f const &)" (?distanceToRay@@YAMABVofVec2f@@00@Z) referenced in function "public: void __thiscall Recognizer::update(class ofPolyline &)" (?update@Recognizer@@QAEXAAVofPolyline@@@Z)

allow properties to be public in RunningBackground

It would be nice for certain properties to be public (threshold, ignoreForeground, differenceMode) to be public as opposed to the setters. Doing this would make it easier to hook up GUI sliders without the extra code to watch and change properties.

Thanks - awesome addon! Let me know if I am missing a better approach.

HSV Tracker doesn't wrap correctly

this means reddish colors may not be tracked correctly. the fix would look something like this:

float minS = clamp(sTarget-20, 0, 255);
float maxS = clamp(sTarget+20, 0, 255);
float minV = 0;
float maxV = 255;
cv::Scalar minRange = cv::Scalar(hTarget - hWidth, minS, minV);
cv::Scalar maxRange = cv::Scalar(hTarget + hWidth, maxS, maxV);
if(minRange[0] < 0)
{
   //negative side
   cv::inRange(hsvImg, cv::Scalar(180+minRange[0], minS, minV) , cv::Scalar(180, maxS, maxV), minMap);
   //positive side
   cv::inRange(hsvImg, cv::Scalar(0, minS, minV), maxRange, maxMap);
   cv::bitwise_or(minMap,maxMap, threshedMap);
   //NSLog(@"less than");
}
else if(maxRange[0] > 180)
{
   //neg side
   cv::inRange(hsvImg, minRange, cv::Scalar(180, maxS, maxV), minMap);
   //pos side
   cv::inRange(hsvImg, cv::Scalar(0, minS, minV), cv::Scalar(180 - maxRange[0], maxS, maxV), maxMap);
   cv::bitwise_or(minMap,maxMap, threshedMap);
   //NSLog(@"more than");
}
else
{
   cv::inRange(hsvImg, minRange, maxRange, threshedMap);
   //NSLog(@"in range.");
}

compile on 10.7 osx Lion

Hey, I am not sure wether its better to ask on the OF forum or here. I know its early stages of this addon but would love to give it a spin especially the flow examples. I cant compile it on my 10.7 lion though, maybe someone has an idea. I only manage to compile the empty example. here is my error output. I changed the build settings to use 10.6 and can compile other OF examples fine

Ld bin/FaceExampleDebug.app/Contents/MacOS/FaceExampleDebug normal i386
cd /Users/tommi/Documents/of007-github/openFrameworks/addons/ofxCv/example-face
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/llvm-g++-4.2 -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/tommi/Documents/of007-github/openFrameworks/addons/ofxCv/example-face/bin -L/Users/tommi/Documents/of007-github/openFrameworks/addons/ofxCv/example-face/../../ofxOpenCv/libs/opencv/lib/osx -L/Users/tommi/Documents/of007-github/openFrameworks/addons/ofxCv/example-face/../../ofxOpenCv/libs/opencv/lib/osx -F/Users/tommi/Documents/of007-github/openFrameworks/addons/ofxCv/example-face/bin -F/Users/tommi/Documents/of007-github/openFrameworks/addons/ofxCv/example-face/../../../libs/glut/lib/osx -filelist /Users/tommi/Library/Developer/Xcode/DerivedData/FaceExample-gfytzcpslprzgcbiyhemcwzzdpwv/Build/Intermediates/FaceExample.build/Debug/FaceExample.build/Objects-normal/i386/FaceExampleDebug.LinkFileList -mmacosx-version-min=10.6 -dead_strip ../../../libs/poco/lib/osx/PocoFoundation.a ../../../libs/poco/lib/osx/PocoNet.a ../../../libs/poco/lib/osx/PocoXML.a ../../../libs/poco/lib/osx/PocoUtil.a ../../../libs/tess2/lib/osx/tess2.a ../../../libs/glew/lib/osx/glew.a ../../../libs/cairo/lib/osx/cairo-script-interpreter.a ../../../libs/cairo/lib/osx/cairo.a ../../../libs/cairo/lib/osx/pixman-1.a ../../../libs/fmodex/lib/osx/libfmodex.dylib ../../../libs/rtAudio/lib/osx/rtAudio.a -framework GLUT /Users/tommi/Documents/of007-github/openFrameworks/libs/openFrameworksCompiled/lib/osx/openFrameworksDebug.a -framework AGL -framework ApplicationServices -framework AudioToolbox -framework Carbon -framework CoreAudio -framework CoreFoundation -framework CoreServices -framework OpenGL -framework QuickTime -framework AppKit -framework Cocoa -framework IOKit /Users/tommi/Documents/of007-github/openFrameworks/addons/ofxCv/example-face/../../ofxOpenCv/libs/opencv/lib/osx/opencv.a -o /Users/tommi/Documents/of007-github/openFrameworks/addons/ofxCv/example-face/bin/FaceExampleDebug.app/Contents/MacOS/FaceExampleDebug

Undefined symbols for architecture i386:
"ofxCv::toOf(cv::Rect_)", referenced from:
testApp::draw() in testApp.o
"ofxCv::toCv(ofBaseHasPixels_&)", referenced from:
void ofxCv::convertColor<ofVideoGrabber, ofImage_ >(ofVideoGrabber&, ofImage_&, int)in testApp.o
"ofxCv::resize(ofImage_&, ofImage_&, int)", referenced from:
testApp::update() in testApp.o
"ofxCv::getTargetChannelsFromCode(int)", referenced from:
void ofxCv::convertColor<ofVideoGrabber, ofImage_ >(ofVideoGrabber&, ofImage_&, int)in testApp.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

Many thanks,
Thomas

calibration camera raises exception

When the chessboard is present in the cam image, then the call to:

bool found = findBoard(img, pointBuf);

returns "true" and then the next instruction:

imagePoints.push_back(pointBuf);

makes the program to raise an exception.

Use a particular version of openCV

or "OpenCV version installed in my system and theo's version"

the wish: i'd like to use a particular version of openCV i have installed in my computer.
the problem: when i get run time error the XCode consolle print: /Users/theo/Downloads/OpenCV-2.3.1 .. version 2.3.1.. not the particular version i want to use
the question: why? how can i change it? how can i understand the real opencv version?

hi
I have installed in my computer opencv 2.4.3. i'm on a macbook pro mac osx 10.8.2.
I know it because if (both in a plain c++ opencv file both in openframeworks) with this cout:

cout << CV_VERSION << endl;

i get as output in consolle: 2.4.3

BUT now i'm fighting with some runtime errors and the error message i get in the consolle is:

OpenCV Error: Assertion failed (k == STD_VECTOR_MAT) in getMat, file /Users/theo/Downloads/OpenCV-2.3.1/modules/core/src/matrix.cpp, line 918
libc++abi.dylib: terminate called throwing an exception

Why it is telling me that the problem is in theo/.../opencv 2.3.1 ?? i don't have opencv version 2.3.1..
I think that version is the one liked in the ofxOpenCV addon.. but i want my 2.4.3 version.
What do i have to do?

I'm using XCode 4.6 but i'm totally new to this IDE..

To tell the truth if i remove che ofxOpenCV directory from my OF/addons XCode says this:

clang: error: no such file or directory: '../../../addons/ofxOpenCv/libs/opencv/lib/osx/opencv.a'

but.. in Build Settings, User-Defined there is nothig saying i have to use ofxOpenCV addon..
now my question is..
why? what is the real opencv version i'm using?

the problem is that i'm using cv::mean and cv::Mat::setTo and there are some difference between opencv last versions, as i understand from this: http://stackoverflow.com/questions/10377400/opencv-inputarray-outputarray

toCv() fails to compile for some parameter calls

toCv() seems to fail for certain parameter inputs where it expects to change the data (ie non const Mat). I'm not sure if I'm using it wrong, but this doesn't compile for me:

cv::Canny(toCv(gray),toCv(lines), mouseX, mouseY, 3);

where as this compiles fine:

Mat linesMat = toCv(lines);
cv::Canny(toCv(gray),linesMat, mouseX, mouseY, 3);

Tracker needs event-style tracking and follower-style tracking

the primary difficulty with designing Tracker is not the tracking algorithm itself -- that's the easy part.

the main problem is allowing it to interface cleanly to other people's code that uses it.

there are three ways i can imagine right now:

  1. list-based, where you call track() and then use the lists like getCurrentLabels() getNewLabels() etc. to update your own objects. but this is hard because you need to maintain a map
  2. event-based, where you register for events like newLabelEvent, deadLabelEvent etc. which is good for objects being introduced/removed, but if you want to have a corresponding collection of objects you still need to maintain a map
  3. follower-based, where you extend the Follower class with your own object, and a TrackerFollower will internally create and destroy Follower objects that correspond to the available labels.

OpenCV version for optical flow

Hey guys,

The newest commits re: optical flow use buildOpticalFlowPyramid, which is openCV 2.4.1+. Apologies if this is somewhere and I just missed it, but is there a set version ofxCv is targeting and a standard guide of upgrading your opencv libs to said version?

gluLookAt in Calibration.cpp stops RPI build

Building ofxCv on RPI fails on the gluLookAt on Calibration.cpp line 71:

"gluLookAt" not declared in this scope

I'm a little confused as this function exists in /usr/include/GL/glu.h ...

Anyway, this is probably an openFrameworks-raspberrypi issue, but thought I'd start here first. Maybe @bakercp knows?

In any case, I commented that line out as we're not using the Calibration class and ofxCv built.

OF 0071 windows ofxcv calibrateCamera() bug (Only CodeBlock)

CalibrationExample.exe has stopped working
"A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available."

In ofxCv Calibration examples,

The same code of 7.0 and of7.1 (vs2010) is normal.

https://github.com/kylemcdonald/ofxCv/tree/master/example-calibration/src

void testApp::update(){
......
if(calibration.add(camMat)) {

cout << "re-calibrating" << endl;

calibration.calibrate();  
......
}
bool Calibration::calibrate() {
....
float rms = calibrateCamera(objectPoints, imagePoints, addedImageSize, cameraMatrix, distCoeffs, boardRotations, boardTranslations, calibFlags);  =>>>>>>bug
......
}
//! finds intrinsic and extrinsic camera parameters from several fews of a known calibration pattern.
CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints,
InputArrayOfArrays imagePoints,
Size imageSize,
CV_OUT InputOutputArray cameraMatrix,
CV_OUT InputOutputArray distCoeffs,
OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs,
int flags=0 );

D:/PROGRA~1/OF_V00~1/apps/ADDONS~1/OFXCVE~1/CALIBR~1/../../../../addons/ofxOpenCv/libs/opencv/include/opencv2/core/operations.hpp:1626 Program received signal SIGSEGV, Segmentation fault. cv::GEMMSingleMul () ()

weird segfault using toCv()

I don't know if it's worth mentioning however I've been experiencing segfaults when using large images.

Gbd points me at cv::threshold... however I tried to reproduce this bug using only openCV but that worked fine. I've found I could work around the segfaults by using toCv() differently.

before:
ofImage load;
load.setUseTexture(false);
load.loadImage(originalsDir.getFile(i));
load.setImageType(OF_IMAGE_GRAYSCALE);
cv::Mat tmp = ofxCv::toCv(load);
after:
ofImage load;
load.setUseTexture(false);
load.loadImage(originalsDir.getFile(i));
cv::Mat tmp = ofxCv::toCv(load);
cv::cvtColor(tmp, tmp, CV_RGB2GRAY);

So load.setImageType(OF_IMAGE_GRAYSCALE); seems to be the issue...
I couldn't find a logical reason in the toCv code.... other than hardware(gpu) limitations in relation with ofImage or some trouble when setting a different image type?

Rg,

Arnaud

Flow rows & cols

The cv::Mat flow is protected wonder the best way to figure out the rows and cols so that you can use getFlowPosition(...) etc. I think that just rows, cols as variables in ofxCv::Flow would work

bug? Calibration needs to use statics more

Currently it's really messy to use the features of calibration outside of the 'standard routine'
e.g. i'm making a system where
N cameras capture scenes
At the time of capture a thread is started to perform the board finding, so each 'BoardFrame instance ends up with a vector, a success flag and a complete flag'
blah blah blah
i end with a spare set of recognised imagePoints and i sift through them
blah blah blah
i'm performing all the data handling (i.e. dealing with imagePoints) outside of the Calibrate class

it'd be great if Calibration's routines were generally static, and Calibration itself called these static functions as and when it needed them (to keep functionality the same as now, but also allow for assistance of calibration outside of a calibration instance)

e.g. bool findBoard(Mat img, vector<Point2f> &pointBuf) could call
findBoard(Mat img, vector<Point2f> &pointBuf, cv::Size patternSize, CalibrationPattern)

also i think CalibrationPattern could be extended into a class which stores the squaresize, patternsize, pattern type

Error Compiling OfxCv in Xcode

I have compiler errors attempting to compile ofxcv, I am using XCode 4.2 and Mac-OS 10.6.8 with OpenFrame Works version 0073 (Latest available.)

The errors are : Semanti Issues in :

  1. Core.hpp
  2. Operations.hpp
  3. matt.hpp

and Apple LLVM Compiler 3.0 Error

Find the snapShots for the errors here :

Error Image1

Error Image 2

I have also placed the OfxCv folder in addons and generated the project through Project Generator.

Even the Ofxcv Examples are also not working (Examples are giving some different compilation errors).

OpenFrameWorks programs and Examples are working fine.

Help me out in solving these errors.

Thanks
Mayank

intrinsics including distortion

i know you don't agree in general on the definition of intrinsics including distortion
but i think it'd be highly practical (and make camera settings more portable) if distortion was included in intrinsics
then intrinsics itself would deal with unprojection, etc
and Calibration's role would generally be to generate intrinsics instances (+stereo and other things)

ofxCv builds for GCC, but not LLVM

addons/ofxCv/libs/ofxCv/include/ofxCv/Utilities.h
addons/ofxCv/libs/ofxCv/include/ofxCv/Utilities.h:31:47: error: call to function 'getCvImageType' that is neither visible in the template definition nor found by argument-dependent lookup [3]

addons/ofxCv/libs/ofxCv/include/ofxCv/Tracker.h
addons/ofxCv/libs/ofxCv/include/ofxCv/Tracker.h:148:25: error: call to function 'trackingDistance' that is neither visible in the template definition nor found by argument-dependent lookup [3]

will look into it anyway

flow-keypoints doesn't compile

line 48 of keypoints example doesn't compile for me

KeyPointsFilter::retainBest(keypointsInside,30);

retainBest cannot be found. is this a OpenCV 2.3 vs 2.4 issue?

include opencv2/opencv.hpp in the ofxCv Header

Hi Kyle,

it makes sense to include "opencv2/opencv.hpp" instead of ""cv.h" and "highgui.h" in the ofxCv Header.

"cv.h" doesn't include the headers for some of tje new opencv 2 features (like background segmentation).

toCV followed by toOf results in unallocated data

setup() {
    _tester.loadImage("logo.png");
}

draw() {
    ofImage img;
    cv::Mat mat;

    mat = ofxCv::toCv( _tester );
    ofxCv::toOf( mat, img );

    _tester.draw(100, 100);
    img.draw(600, 100);

}

The result is flashing unallocated data. I did some digging around and it seems that a passive pixel copying is happening deep down, so when I declare
ofImage img;
cv::Mat mat;
in the header file the flashing disappears and I get a black image.

Either way I'd say this isn't what is expected.

TEMP VARIABLES
Screen Shot 2013-02-01 at 4 59 23 PM
Screen Shot 2013-02-01 at 4 59 31 PM

DEFINED IN H
Screen Shot 2013-02-01 at 5 02 12 PM

undefined reference to `distanceToEllipse(ofVec2f const&

I have error when compile example-gesture :
I am using Codeblock with MinGW compiler and I didn't have issue so far with your another examples.

Error Message :
obj\release\src\testApp.o:testApp.cpp:(.text$_ZN10Recognizer6updateER10ofPolyline[Recognizer::update(ofPolyline&)]+0x117): undefined reference to distanceToEllipse(ofVec2f const&, cv::RotatedRect const&)' obj\release\src\testApp.o:testApp.cpp:(.text$_ZN10Recognizer6updateER10ofPolyline[Recognizer::update(ofPolyline&)]+0x1f1): undefined reference toclosestPointOnRay(ofVec2f const&, ofVec2f const&, ofVec2f const&)'
obj\release\src\testApp.o:testApp.cpp:(.text$_ZN10Recognizer6updateER10ofPolyline[Recognizer::update(ofPolyline&)]+0x25c): undefined reference to `closestPointOnRay(ofVec2f const&, ofVec2f const&, ofVec2f const&)'

ofPoint matchRegion() missing return?

ofPoint matchRegion(ofImage& source, ofRectangle& region, ofImage& search) {
FloatImage result;

    imitate(result, source);

}

sorry,i tried to complied the code under the vs2010,its saying that block of code must be return something,also,i have to add
those within the ofxCv.cpp

typedef signed char int8_t;
typedef signed short int16_t;
typedef signed long int32_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;

thxs!

runningbackground.h compile errors in VS2010

When I attempt to compile, I get this list of errors:

2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(39): error C2059: syntax error : 'constant'
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(39): error C2143: syntax error : missing ';' before '}'
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(39): error C2238: unexpected token(s) preceding ';'
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(41): error C2059: syntax error : ')'
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(56): error C2065: 'DifferenceMode' : undeclared identifier
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(56): error C2146: syntax error : missing ')' before identifier 'differenceMode'
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(56): error C2182: 'setDifferenceMode' : illegal use of type 'void'
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(56): error C2059: syntax error : ')'
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(58): error C2059: syntax error : 'protected'
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(63): error C2146: syntax error : missing ';' before identifier 'differenceMode'
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(63): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(63): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(65): error C2059: syntax error : '}'
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(65): error C2143: syntax error : missing ';' before '}'
2>c:\users\momo\documents\of_prerelease_v007_vs2010\addons\ofxcv\libs\ofxcv\include\ofxcv\runningbackground.h(65): error C2059: syntax error : '}'

ContourFinder getCountours as const disables draw without copy?

0d50e51#L23R47

Before the above change I was able to do this:

for (int i=0; i<contourFinder.getPolylines().size(); i++)  {
  contourFinder.getPolylines()[i].draw();
 }

I now get this error:
error: passing 'const ofPolyline' as 'this' argument of 'void ofPolyline::draw()' discards qualifiers

I can do the below this but isn't this copying the vector every time?

vector<ofPolyline> polylines =  contourFinder.getPolylines();
for (int i=0; i<polylines.size(); i++) {
  polylines[i].draw();
}

come on! remove this :)

include "ofxCv/Utilities.h"

include "ofxCv/Wrappers.h"

include "ofxCv/Helpers.h"

include "ofxCv/Distance.h"

include "ofxCv/Calibration.h"

include "ofxCv/ContourFinder.h"

include "ofxCv/Tracker.h"

include "ofxCv/RunningBackground.h"

i know mirroring opencv is what awesome people do
but for an ofx, it's non-standard and unnecessarily painful to faff with the search path
i'm not sure if there's any necessary advantage to this

implement a clamp() function

it's a common enough operation, but using min/max isn't always obvious. something like this:

// clamp out of place
template <class S, class D>
void clamp(S& src, float lowerBound, float upperBound, D& dst) {
    ofxCv::min(ofxCv::max(src, lowerBound), upperBound, dst);
}

// clamp in place
template <class SD>
void clamp(SD& srcDst, float lowerBound, float upperBound) {
    ofxCv::min(ofxCv::max(srcDst, lowerBound), upperBound, srcDst);
}

this requires ofxCv::min/max to be defined as well.

also see http://stackoverflow.com/questions/7552896/most-efficient-way-to-clamp-values-in-an-opencv-mat

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.