MATLAB Answers

realtime data streaming between matlab and opencv, visual c++

5 views (last 30 days)
newbie
newbie on 22 Jun 2012
My C program tracks any particular colour in a video and prints the coordinates of that point. I want to write a matlab program which can take these coordinates as input and analyse them.I am doing all this in windows XP. I have read about mex files and also about the memory mapping but, nothing is working.
When I build my mex file, it shows many errors with the core.hpp file like:
"ptrdiff does not belong to the class std"
can anyone help?

Answers (1)

Geoff
Geoff on 24 Jun 2012
How "realtime" do you need? If you were polling a file multiple times a second, would that be sufficient? Can you do your analysis in blocks, or must it be live? After analysis in MatLab, do you need to deliver a result back to the C++ program? How complicated is your analysis - ie is there any reason not to do it in C++?
The best option in my opinion would be to try and get UDP communication going. Have your tracking application simply fire off the coordinates to localhost using UDP on some port. If your MatLab script is listening, it will start receiving the data and can do something with it. If it needs to communicate back, have it fire off UDP packets on a different port, which your tracker is listening on.
Presumably you are comfortable with threading, synchronisation and network communications?
A quick Google search pulled up something vaguely promising:
Or there is TCP/IP code if you feel like bashing your head against a wall:
But if polling a little file is responsive enough, do that. I would just use binary so I could be sure I had read the entire co-ordinate. I'd know how many bytes to expect and, if I appended to the file (preferable to avoid syncronisation issues or data corruption) it would contain a complete record for post-analysis if necessary.
  9 Comments
Geoff
Geoff on 27 Jun 2012
Okay, had some more fun with this. I ported my Sink code to MatLab and confirmed this method works fine - average lag was 0.05% of a frame with very occasional peaks up to about 2%. No frame dropping observed. Caveat is that you need to busy-wait (ie poll the file stupidly fast) or MEX a better pause() function. I would take the simplest route and poll very fast, because this at worst is only going to max out one core. Anyway, that core is going to spend the rest of its time processing co-ordinates, so getting hold of a co-ordinate ASAP means you have about 30ms to process it.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by