Information exchange between LUA & C ++?

Hello

Well, I was needing to use the OpenCv library in Corona SDK , I asked a question here in the forum myself and found that I could work with C ++ code as well (I still have questions if this works well for windows), so by taking a look I found about connecting LUA and C ++ in this link :

https://gist.github.com/Shchvova/68a3c667327ff33e3cfe0ccd7474135c

 

So what I want to do is a classified traffic count, there are several links with already created projects of this, but that’s not what I need, I’ll post some examples:

https://github.com/alex-drake/OpenCV-Traffic-Counter

https://github.com/ahmetozlu/vehicle_counting_tensorflow

https://github.com/andrewssobral/simple_vehicle_counting

 

Relevant issues

1 - ** Why are not these projects what you need?**

Because this is just doing a count of the vehicles that go through the line without sorting them (like car, motorcycle, bus and truck), and another question is, is performing the count in just one line.

2- What does the project need to do?

I need to do pretty much what these git projects already do, even if I can use them it will be great!

I will do exactly this to perform the count after going through a line but, the program will have to perform a different count for each type of vehicle category (car, motorcycle, bus, truck).

And I will also make the person can draw the lines on top of the video, thus making a project more global, can count on more than one street at a time

3- What exactly do you want to ask in this topic?

Well, now that I’ve explained the project, you can better understand the need for this question.

As I said before, the user can draw lines on top of the video, right? But to draw these lines, the corona would make me a lot easier, so my idea is to allow the user to draw these lines on the corona platform, and after it has finished, the corona sends the information to the code in c ++ (because it will be the one that will be with all the main code, since I believe it is impossible to do this using only the crown).

After you have finished undoing the video, you will have a “play” button where you will start the video and perform the whole count, and the data of this count will be stored in the code in C ++, so to create a text file in the repository, I need to send the code information in C ++ for the LUA and it has the array with all the count information.

Now …  How can I do this transfer of information between the two codes and test it on the corona simulator?  Can someone help me ?

Note: If you have a suggestion for a better method, I would also like to hear it!

Hi.  First forgive me, but I’m only going to answer part of your post.  

  1. Assuming you understand how the Corona native example frameworks work, you can definitely integrate C and C++ code into your game/app using Corona Native. 

My expectation is you’d create a plugin for the library you want to integrate, then build that into your project using the normal build process.  To do this, the plugin will need to be hosted by Corona or yourself.  i.e.  You can choose to sell the plugin, give it away for free, or self-host it.  

Please note, I have never used corona native to directly build a Windows or OSX binary that integrates an external library, but that may also be a possibility. 

2.  If you ONLY care about Windows, you’ll need a Windows machine.  If you also want to target OS X and/or iOS you’ll need an OS X machine too.

3.  I have not looked at the projects you linked (again sorry but I’m just peeking here and then getting back to work).

4.   Whether you choose to create plugins then to require them OR if you figure out how to build Windows/OS X binaries via Corona Native, you will need to do some heavy lifting to get the libraries integrated into your project. 

Using the example code supplied with the libraries you want to integrate wont’ get you very far.

You can certainly refer to their examples, but you’ll still need to do the following on your own:

  • copy source to your project so it can be built and linked in.
  • update your build projects for the different target OSes to build and link in the libraries.
  • Write your own plugin/hooks to get the code into your project and expose the library’s APIs to Corona
  • Write Lua scripts to require the plugin(s) and use the API.

This is some serious coding work so if you’re not already a skilled Native coder you may have a big challenge ahead of you.

@everyone,

If anyone else wants to add responses, elaborate on my response, or say I’m wrong please do.  I just wanted to note this is possible, but not an insignificant task.

PS - I wouldn’t be searching the web first.  I’d start here: https://docs.coronalabs.com/native/index.html

If you can download, build, run, modify, re-build and understand the sample projects found in those docs you’ll be able to get started on this.

PPS - I am making a huge assumption in my answer above.  The last time I did this, there were projects available that could be built for: Windows, OSX, iOS, and Android. 

IIRC I used the open source bit library example as a basis for my own plugin work.  It comes ready-to-build for all those targets.

If you can’t find this code I would ask that a staff member supply a link or give you other directions.

Note: I almost didn’t answer this post and in retrospect maybe I should not have.  

I don’t enjoy native coding because you constantly have to race to keep up with changes (and I’m not talking about Corona here, but the other parts not under their control.) 

This is the same reason I love Corona.  Why code a game/app in native code when one has an easy and powerful API that Corona maintains and keeps working regardless of Android / iOS / Windows / OS X / ++ changes.

In your case, you really can’t avoid the deep dive into the gory guts of Native code.  Sorry.

roaming I read this twice and started a response and didn’t. Corona or not Corona is the smallest of problems that you Pablo. First, you need a machine learning API since I don’t believe OpenCV can distinguish between a car and a truck by itself. You need something like Caffe. I don’t know if it works on Windows but I imagine you can use other machine learning libraries. When I mention Caffe from now on I mention any machine learning api. You would then need to integrate OpenCV to Caffe. Then you have to create a model and feed Caffe a bunch of pictures. Test… Feed. Test… Feed. Maybe even update the model. Then I would test it with 1 lane. Caffe can do millions of evaluations in one day with one CUDA video card but who knows how fast these cars are going through and what kind of hardware you would need. Then I would worry about drawing anything. But this is my opinion and maybe who knows you have everything else figured out.

First … WOW

You say you do not answer all of the questions in the but, this one answer is enough to completely understand where you wanted to go.

(off: many say that Brazilians are very receptive and affectionate, but when I ask something here in the Corona forum I see that gringos are also very attentive)

Well, I also like the Corona precisely because of what you mentioned, and even that was my ambition to use the corona in this project because it is simply incredible. But, I did not want to depend on so many external resources, which apparently is what will have to happen … =

I probably will not use Corona on this project, not for the reason that it’s bad, but for the reason that it complicates my whole life to use it along with opencv.

I did not want to resort to this but apparently I will have to use Java to do what I want.

Thanks for the help @roaming :wink:

Hey buddy,

Opencv allows you to differentiate car from truck after you make some modifications, I do not know how it works abroad, but here in Brazil we have a public agency of the state (I know that outside of Brazil there are no organs exclusively of the state, but, here it is literally all a mess) that categorizes ALL vehicles and REQUIRES to follow all a pattern, so with this we can differentiate each category by using only openCv :wink:

Very cool.

Hi.  First forgive me, but I’m only going to answer part of your post.  

  1. Assuming you understand how the Corona native example frameworks work, you can definitely integrate C and C++ code into your game/app using Corona Native. 

My expectation is you’d create a plugin for the library you want to integrate, then build that into your project using the normal build process.  To do this, the plugin will need to be hosted by Corona or yourself.  i.e.  You can choose to sell the plugin, give it away for free, or self-host it.  

Please note, I have never used corona native to directly build a Windows or OSX binary that integrates an external library, but that may also be a possibility. 

2.  If you ONLY care about Windows, you’ll need a Windows machine.  If you also want to target OS X and/or iOS you’ll need an OS X machine too.

3.  I have not looked at the projects you linked (again sorry but I’m just peeking here and then getting back to work).

4.   Whether you choose to create plugins then to require them OR if you figure out how to build Windows/OS X binaries via Corona Native, you will need to do some heavy lifting to get the libraries integrated into your project. 

Using the example code supplied with the libraries you want to integrate wont’ get you very far.

You can certainly refer to their examples, but you’ll still need to do the following on your own:

  • copy source to your project so it can be built and linked in.
  • update your build projects for the different target OSes to build and link in the libraries.
  • Write your own plugin/hooks to get the code into your project and expose the library’s APIs to Corona
  • Write Lua scripts to require the plugin(s) and use the API.

This is some serious coding work so if you’re not already a skilled Native coder you may have a big challenge ahead of you.

@everyone,

If anyone else wants to add responses, elaborate on my response, or say I’m wrong please do.  I just wanted to note this is possible, but not an insignificant task.

PS - I wouldn’t be searching the web first.  I’d start here: https://docs.coronalabs.com/native/index.html

If you can download, build, run, modify, re-build and understand the sample projects found in those docs you’ll be able to get started on this.

PPS - I am making a huge assumption in my answer above.  The last time I did this, there were projects available that could be built for: Windows, OSX, iOS, and Android. 

IIRC I used the open source bit library example as a basis for my own plugin work.  It comes ready-to-build for all those targets.

If you can’t find this code I would ask that a staff member supply a link or give you other directions.

Note: I almost didn’t answer this post and in retrospect maybe I should not have.  

I don’t enjoy native coding because you constantly have to race to keep up with changes (and I’m not talking about Corona here, but the other parts not under their control.) 

This is the same reason I love Corona.  Why code a game/app in native code when one has an easy and powerful API that Corona maintains and keeps working regardless of Android / iOS / Windows / OS X / ++ changes.

In your case, you really can’t avoid the deep dive into the gory guts of Native code.  Sorry.

roaming I read this twice and started a response and didn’t. Corona or not Corona is the smallest of problems that you Pablo. First, you need a machine learning API since I don’t believe OpenCV can distinguish between a car and a truck by itself. You need something like Caffe. I don’t know if it works on Windows but I imagine you can use other machine learning libraries. When I mention Caffe from now on I mention any machine learning api. You would then need to integrate OpenCV to Caffe. Then you have to create a model and feed Caffe a bunch of pictures. Test… Feed. Test… Feed. Maybe even update the model. Then I would test it with 1 lane. Caffe can do millions of evaluations in one day with one CUDA video card but who knows how fast these cars are going through and what kind of hardware you would need. Then I would worry about drawing anything. But this is my opinion and maybe who knows you have everything else figured out.

First … WOW

You say you do not answer all of the questions in the but, this one answer is enough to completely understand where you wanted to go.

(off: many say that Brazilians are very receptive and affectionate, but when I ask something here in the Corona forum I see that gringos are also very attentive)

Well, I also like the Corona precisely because of what you mentioned, and even that was my ambition to use the corona in this project because it is simply incredible. But, I did not want to depend on so many external resources, which apparently is what will have to happen … =

I probably will not use Corona on this project, not for the reason that it’s bad, but for the reason that it complicates my whole life to use it along with opencv.

I did not want to resort to this but apparently I will have to use Java to do what I want.

Thanks for the help @roaming :wink:

Hey buddy,

Opencv allows you to differentiate car from truck after you make some modifications, I do not know how it works abroad, but here in Brazil we have a public agency of the state (I know that outside of Brazil there are no organs exclusively of the state, but, here it is literally all a mess) that categorizes ALL vehicles and REQUIRES to follow all a pattern, so with this we can differentiate each category by using only openCv :wink:

Very cool.