Command Bar Option that Chooses a Folder

rhino
screencapture
rhinocommon

(Ibrahim Mahmoud) #1

I want to add an animation feature to my plugin using RhinoCommon, and I was able to implement screenshots in it and save them to a constant directory.

This can be made to be more convenient by allowing the user to choose which directory to save the screenshots in, but I’m not sure how to make a command bar option that allows you to do so and save the desired folder.

How would I accomplish my goal?

Also, if this is possible, is there a way to programmatically convert a list of pictures to a video file, like .avi or .mp4, using C#? That would be helpful as well.


#2

rhinocommon runs in .net, ergo you have any number of video routines you can incorporate, I recommend emgu.cv if you need to get fancy otherwise .net already includes many basic image manipulation tools, pull emgu or simplecv from nuget. If you want gif I do recommend NOT using the .net available option and google for an api to include, .net natives wont allow frame timing. I wrote my own code to inject the delay bits between frames,

if you can avoid gif you are better off, but if you need the source for my capture app gif routine (see later in this video below) im happy to share, it was poached from an 80% useful python linux code I stumbled into.

if python is your weapon of choice there are a few .py’s around the place on the RPi forum that can help with GIF. Video in python is alo OpenCV, but no luck with simplifying the process as with simplecv or emgu.cv unfortunately, a lot fo code is longhand. Same app, same GIF function, but python/linux.

In terms of selecting a folder, that already exists in both the rhinocommon and .net filedialog option.

hth.


(Steve Baer) #3

You can use a FolderBrowserDialog for this
https://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog(v=vs.110).aspx

It looks like there are several libraries out there that provide support for encoding video files. I just searched for “C# mp4 encoder” and got quite a few hits. I don’t have experience with these libraries so I can’t really make any recommendations.


#4

this tickled me so I wrote one. I used the SHARP library and encode directly from the BITMAP object created by

Bitmap image = newview.CaptureToBitmap(size, false, false, false);

Nothing temporary written to disc except the video of about ~16-18mb. mjpeg codec in this clip but you can use one of about 10 supported codecs, the h264 codec gets same file down to 3mb…, but I stuck to mjpeg because its native in ALL windows installs… there is nothing worse than “you don’t have the correct codec to play this file…”

use your googlefu or nuget for the sharp library.

usage:

output:



(Ibrahim Mahmoud) #5

Wow, was that GUI your creation? Did you have to convert the python code to c#?

I’m definitely going to look more into emgu.cv, now that I just got my folder browser option operational. Thank you very much for your help!


(Ibrahim Mahmoud) #6

Thanks for your help, I got my folder browsing option working now!


#7

Not emgu. Sharp. I use emgu for my camera apication but its top heavy for this kind of thing. Sharp was dead simple.


(Ibrahim Mahmoud) #8

Where do I find this SHARP library? I’m not sure what you’re referring to
here.


(Ibrahim Mahmoud) #9

Is this it?


#10

Oops the library is called sharpavi not sharp. My apologies.


#11

I only use Python in linux. Its a great language, akin to Basic in simplicity but the same simplicity can make it a major pita for someone that likes structure.


(Ibrahim Mahmoud) #12

I’ve used Python before, but I was introduced to it years after I’ve developed a taste for languages like Java and C#. Thanks for the library recommendation, I got it to work! I found a different library that can convert video file types, and this website doesn’t allow .avi files to be uploaded, which is why I present a .mp4 file rather than a .avi file.


#13

Glad you got sorted. Easier to just pop it on youtube and paste link here.


#14

also… just FYI… if you have to write to disc and read back, forget windows giving you an easy to use human readable list of the files, it put 2 just after 20, 1 just after ten, the string weights are lower… but this works.


#15

so used that sharpavi library in my other project, handy little thing isnt it… used it to backward engineer my GIF output too, the mjpeg output is far better than the native .net GIF handler.



(Ibrahim Mahmoud) #16

It looks pretty good, how long did it take to reverse engineer it? My only concern is that the zoom function doesn’t retain its original resolution, it seems to be a bit more pixilated than the original.


#17

depends on the webcam you use, some webcams will actually digital zoom, but most simply use native resolution ex 1080p, and will crop the perimeter border down to 960, 720p, 640p, 540p, 480p etc etc while keeping the same “resolution” as it were.

Second video above is 480P from a 720p webcam. Images of the build here:

to turn a regular cheap webcam into a macro cam is pretty easy too. remove the CCD lens housing and put a spacer under it, something spongy if you can, which allows you to screw it back to find the best focal distance without inducing too much DOF.