I have a C++ project using OpenCV for some operations with images (visual studio 2010; opencv2.4.9). I need make rails app with functions of my project on C++. Moreover I need give some parameters from rails app to C project and take result to rails app. How can i do it? P.s.: OpenCV for ruby not suitable for me.
-
1http://chris911.github.io/blog/2014/08/10/writing-a-ruby-gem-with-c-extension/ – max Oct 24 '15 at 11:16
2 Answers
You could use backticks, or %x()
to execute your C++ program. It's just like you would execute it from a terminal, i.e. %x(/path/to/your/C++/executable parameter1 parameter2)
For more information on this, see this question.
@tschale already mentioned a solution. Here is a more elaborate solution that you would use if your code is expected to be put on the internet or internal network anytime soon.
Get a message queue - redis, beanstalkd, rabbitmq. This is a third executable that you need to run on your web host. This executable provides REST APIs for updating the queue.
If your rails app wants to do a task, it would push a message onto this queue. The message would look something like this:
{
"task": "run_facedetect",
"param1": "something",
"param2": {
"detail1": 45
...
}
}
(I'm using JSON only as an example. You're free to use any encoding you want).
The rails app only has to push to queue and it is done.
Now your C/C++ application is listening to the queue (using the REST api). As soon as it sees a message, it spawns a facedetect
app with the given parameters. Once done, the results are stored in a place where you rails app can read it.

- 3,295
- 4
- 30
- 46