Save a Video using irrlecht pychrono

158 views
Skip to first unread message

Declan Mulroy

unread,
Jul 9, 2020, 2:15:44 PM7/9/20
to ProjectChrono
Hello, 

I was scrolling threw the source code for irrlicht.py and was not sure  if any of these commands can be used?



 def SetVideoframeSave(self, val):
        """SetVideoframeSave(ChIrrAppInterface self, bool val)"""
        return _irrlicht.ChIrrAppInterface_SetVideoframeSave(self, val)


    def GetVideoframeSave(self):
        """GetVideoframeSave(ChIrrAppInterface self) -> bool"""
        return _irrlicht.ChIrrAppInterface_GetVideoframeSave(self)


    def SetVideoframeSaveInterval(self, val):
        """SetVideoframeSaveInterval(ChIrrAppInterface self, int val)"""
        return _irrlicht.ChIrrAppInterface_SetVideoframeSaveInterval(self, val)


    def GetVideoframeSaveInterval(self):
        """GetVideoframeSaveInterval(ChIrrAppInterface self) -> int"""
        return _irrlicht.ChIrrAppInterface_GetVideoframeSaveInterval(self)

Another question Is there a way to show the time passed in POV Ray?


Thanks, 

Declan Mulroy


Qiyuan Zhou

unread,
Jul 9, 2020, 4:57:41 PM7/9/20
to ProjectChrono
Hi Declan

You can save frames from Irrlicht in Python by adding the highlighted lines:

            myapplication = chronoirr.ChIrrApp(self.my_system,self.sim, chronoirr.dimension2du(1600,1200))
            myapplication.AddTypicalSky()
            myapplication.AddTypicalLogo('logo_pychrono_alpha.png')
            myapplication.AddTypicalCamera(chronoirr.vector3df(0,2,.75),chronoirr.vector3df(0,0,.75))
            myapplication.SetSymbolscale(.002)
            myapplication.SetShowInfos(True)
            myapplication.SetContactsDrawMode(2)
            myapplication.SetPaused(True)
            myapplication.AddLightWithShadow(chronoirr.vector3df(2,5,2),chronoirr.vector3df(2,2,2),10,2,10,120)

            myapplication.DrawAll               
            myapplication.AssetBindAll();
            myapplication.AssetUpdateAll();
            myapplication.AddShadowAll();
            myapplication.SetTimestep(self.tstep)
            myapplication.SetTryRealtime(False)

            while(myapplication.GetDevice().run()):
                myapplication.BeginScene()
                myapplication.DrawAll()
                print ('time=', self.my_system.GetChTime())
                # run step
                myapplication.DoStep()
                myapplication.EndScene()
                # save data
                myapplication.SetVideoframeSave(True)
                myapplication.SetVideoframeSaveInterval(10)
                # Close the simulation if time ends
                if self.my_system.GetChTime()> self.tend:
                    myapplication.GetDevice().closeDevice()

These frames are then by default saved in the same directory as the .py file as your model under a directory named "video_capture"

Alessandro Tasora

unread,
Jul 10, 2020, 9:26:43 AM7/10/20
to projec...@googlegroups.com

hi

use myapp.SetVideoframeSave(True) to enable automatic saving of all frames to disk (look same folder of the app to see the bmp files).

Use myapp.SetVideoframeSaveInterval(5) for example to save just 1 frame each 5. Default is 1.

Note that -given a limitation in Irrlicht screen grabbing code- if you move some window in front of the Irrlicht 3d view, the first window will 'cover' the second.

Alessandro Tasora

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/ba69a09e-0eb3-47a8-b2d7-5e2f1b32e231o%40googlegroups.com.

Declan Mulroy

unread,
Jul 10, 2020, 12:05:48 PM7/10/20
to Alessandro Tasora, ProjectChrono
Excellent. Thanks Alessandro and Qiyuan!




--
--
Declan Mulroy
Direct: (847)-767-3222
PhD Student at  Armour College of Engineering
Illinois Institute of Technology

Declan Mulroy

unread,
Aug 19, 2020, 12:21:43 PM8/19/20
to ProjectChrono
Just a follow up question, 

Is there a way to save the images out to a specified folder? 
Right now it exports the images to video_capture but I wanted to see if I could export the images to a new folder say called sim_1? 


Thank you, 

Declan 
To unsubscribe from this group and stop receiving emails from it, send an email to projectchrono+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchrono+unsubscribe@googlegroups.com.

Radu Serban

unread,
Aug 20, 2020, 4:06:16 AM8/20/20
to projec...@googlegroups.com

Yes, you can do that but you will have to invoke the Irrlicht functions yourself.
As an example, look at demo_VEH_M113 (https://github.com/projectchrono/chrono/blob/develop/src/demos/vehicle/demo_M113/demo_VEH_M113.cpp) lines 295-300 and at the implementation of the Chrono::Vehicle function ChVehicleIrrApp::WriteImageToFile (https://github.com/projectchrono/chrono/blob/develop/src/chrono_vehicle/utils/ChVehicleIrrApp.cpp) lines 411-417.

--Radu

To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/00725055-203b-4c8a-aeb1-ab4f7d29abffo%40googlegroups.com.

Declan Mulroy

unread,
Aug 20, 2020, 11:56:53 AM8/20/20
to Radu Serban, ProjectChrono
Excellent. Thanks radu. I'm doing it in pychrono so I wrote it out like this shown below which I thought is similar 

file="filename" # <-directory im saving the images too  
 image=self.myapplication.GetVideoDriver().createScreenShot()
self.myapplication.GetVideoDriver().writeImageToFile(image,file);

but I keep getting this error 


Not ImplementedError: Wrong number or type of arguments for overloaded function 'IVideoDriver_writeImageToFile'.
  Possible C/C++ prototypes are:
    irr::video::IVideoDriver::writeImageToFile(irr::video::IImage *,irr::io::path const &,irr::u32)
    irr::video::IVideoDriver::writeImageToFile(irr::video::IImage *,irr::io::path const &)
    irr::video::IVideoDriver::writeImageToFile(irr::video::IImage *,irr::io::IWriteFile *,irr::u32)
    irr::video::IVideoDriver::writeImageToFile(irr::video::IImage *,irr::io::IWriteFile *)

I'm not entirely sure what I'm doing wrong.


Thank you in advance,


Declan 

To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/8b1d16f5-332a-2381-fbc7-64e0056105db%40ied.unipr.it.


--
--
Declan Mulroy
Direct: (847)-767-3222
PhD Student at  Armour College of Engineering
Illinois Institute of Technology
--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/00725055-203b-4c8a-aeb1-ab4f7d29abffo%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages