Ask Your Question

hilton bristow's profile - activity

2015-12-01 20:51:45 -0600 received badge  Notable Question (source)
2014-09-19 03:06:54 -0600 received badge  Popular Question (source)
2014-07-03 03:37:31 -0600 received badge  Nice Answer (source)
2013-08-16 00:12:49 -0600 received badge  Self-Learner (source)
2013-08-16 00:12:46 -0600 received badge  Self-Learner (source)
2013-08-16 00:12:41 -0600 received badge  Teacher (source)
2013-08-16 00:12:34 -0600 received badge  Great Question (source)
2013-06-13 20:47:33 -0600 commented answer Using Matlab data files (.mat) in C++

As part of my GSOC project I'll be adding Matlab file support to OpenCV. It should see its way into early versions of OpenCV 3.x. In the meantime, matio is indeed a good option.

2013-06-13 20:44:32 -0600 commented question Matlab API for OpenCV

Our project got accepted!

2013-04-07 09:23:39 -0600 received badge  Self-Learner (source)
2013-04-07 09:23:27 -0600 received badge  Self-Learner (source)
2013-03-19 20:27:29 -0600 answered a question Matlab API for OpenCV

Detail 4: Finding Matlab

The FindMatlab.cmake distributed with cmake by KitWare is woefully inadequate at finding any recent releases of Matlab. So it's time to write a new one. With a bit of crowd-sourcing I've been able to come up with the default install paths of Matlab on different architectures (in order of likelihood)

Linux: /usr/local /opt/local /usr /opt

Apple: /Applications /usr/local /opt/local /usr /opt

Windows: C:\Program Files C:\Program Files (x86)

In the case of Windows machines, assuming everything is in C: is a baaaad idea, so there are (gulp) recommended methods of hunting through the registry for paths:

execute_process(COMMAND reg query HKLM\\SOFTWARE\\MathWorks\\MATLAB /f * /k)

In the case of Unix derivatives, grep and regex are your friends.

OpenCV eschews the regular package finding convention of find_package(<package>) which locates a Find<package>.cmake file on the CMAKE_MODULE_PATH, in favour of having all the packages called OpenCV[Find/Detect]<package>.cmake and then simply including them in the root CMakeLists.txt as include(cmake/OpenCV[Find/Deteect]<package>.cmake). This is for one very simple and deliberate reason:

They want to make sure their own cmake files are loaded and not other ones on the system

2013-03-18 19:30:00 -0600 received badge  Editor (source)
2013-03-18 19:17:25 -0600 answered a question Matlab API for OpenCV

Detail 3: Other useful utilities

As part of writing the code generator, it would be useful to expose some utilities that make it easier to use OpenCV constructs in mex files, and Matlab features in OpenCV. I was thinking of implementing:

  • Matlab (.mat) I/O for cv::FileStorage. I have an implementation which needs refactoring.
  • A mex script which automatically finds OpenCV and adds the relevant build flags, so compiling your own C++ function containing OpenCV declarations within matlab should be as simple as:

    cvmex my_awesome_function.cpp

  • Conversion class/operations for easily getting between mxArray and cv:: std:: types

What would you like to see?

2013-03-18 19:03:20 -0600 answered a question Matlab API for OpenCV

Detail 2: OpenCV classes in Matlab

There is no ideal solution to referencing C++ classes from Matlab. A set of best practices have been devised by the Matlab community that results in the least amount of undefined behaviour, memory leaks, dangling pointers, etc.

Even so, this requires that the memory address of the C++ object be passed back to Matlab (as a uint64_t) and trusted in the hands of the user (though it is private and invisible).

A better way to do this is to store all of the object instances in a map:

static std::unordered_map<KeyType, OpenCVClass> instances_;

and then give the user a key to accessing their object. That way, if they attempt to modify their key, they'll get a std:out_of_range exception, rather than a segfault. Memory addresses of the objects make good keys since they're not contiguous, so it'll be harder for the user to "guess" another valid instance.

2013-03-18 18:44:13 -0600 commented question Matlab API for OpenCV

Google Summer of Code starts on June 17: http://www.google-melange.com/gsoc/events/google/gsoc2013. Assuming we get the project approved, it should be completed a few months after that. It is therefore likely going to miss the OpenCV 2.5 release.

2013-03-18 18:40:14 -0600 answered a question Matlab API for OpenCV

Detail 1: Conversion types

The excellent mexopencv utility uses a conversion type called MxArray as a means of converting to and from native Matlab (mxArray) and OpenCV and related types (cv::Mat, std::string, etc). Do you like this type of encapsulation, and if so do you prefer explicit conversion (assuming here prhs is of type mxArray**):

std::string name = MxArray(prhs[0]).toString();

or implicit conversion:

std::string name = MxArray(prhs[0]);

Or would you rather a set of utility functions that make memcopys and ownership more explicit:

std::string name = mxArrayToString(prhs[0]);
2013-03-18 12:52:30 -0600 received badge  Good Question (source)
2013-03-18 02:36:51 -0600 received badge  Nice Question (source)
2013-03-18 00:45:13 -0600 received badge  Student (source)
2013-03-17 18:40:27 -0600 asked a question Matlab API for OpenCV

There has been a lot of public interest in Matlab/Octave wrappers for some time now, so we are taking this project on board and aim to have a wrapper generator available within a few months. I will be leading this project under the supervision of Vincent Rabaud and Vadim Pisarevsky. For those who don't know me, I'm a computer vision PhD student and a long time lover of Matlab.

What we would like within this Q&A is to open the floor to suggestions on implementation details. I've already mapped out 96% of the code, but I'm always willing to listen if people have particular requests.