Video Stream

any question related to our SDK and driver

Moderators: yang, Support@ZWO

Post Reply
Chopperkirks
Posts: 6
Joined: Thu Mar 26, 2020 10:29 am

Video Stream

Post by Chopperkirks » Tue Mar 31, 2020 9:19 am

Hi

I am using a 290MM and a 290MC together as a multispectral imaging setup for agriculture ( a bit off from what they are made for) and I need to have a window (or 2) open showing a live feed from the cameras. I have managed to set up the code to open the cameras, take a picture and save it but is there a way to get a live feed from the camera?

MonsterMax
Posts: 13
Joined: Thu Oct 13, 2016 4:32 pm

Re: Video Stream

Post by MonsterMax » Wed Apr 01, 2020 12:22 pm

Hi, which hardware, software, operating system and programming language are you using? You could try ASI Studio for a start.

Chopperkirks
Posts: 6
Joined: Thu Mar 26, 2020 10:29 am

Re: Video Stream

Post by Chopperkirks » Wed Apr 01, 2020 12:32 pm

At the moment I am using Visual Studio to write the program in C++ with opencv. Once I get it working I am Going to move across to either a raspberry pi or a Jetson nano. The problem with using asi studio is firstly, the gui for the Jetson nano cannot be accessed remotely. Also it is necessary for both cameras to be operating at the same time and taking images at the same time to improve the accuracy of the measurements.

MonsterMax
Posts: 13
Joined: Thu Oct 13, 2016 4:32 pm

Re: Video Stream

Post by MonsterMax » Wed Apr 01, 2020 2:56 pm

Ok, I think you have three options:

1) Write the stuff yourself. I once did that using Qt, worked quite well but cost me a lot of nerves. You create some display widget and draw an image within that. If you want interactive control over the program you probably have to work with signals and slots and possibly several threads, a main thread, a capturing thread and a display thread. You can look at the source code of various projects, but think of the licensing terms.

https://github.com/openastroproject/openastro
https://github.com/GuLinux/PlanetaryImager
https://github.com/chmorgan/sharppcap (C#)

You could of course use some other GUI-Toolkit like GTK or TK, or work with opencv like you do, but there I'm completely lost.

2) If you know python, there is a python wrapper for the SDK. This might make the visualization easier.

3) If you like to live dangerously, you can try the julia wrapper which I wrote for the ZWO SDK:

https://github.com/AlfTetzlaff/LibASICamera.jl

You have to install julia, add the Makie package, my package and follow the given example. This runs at 20fps@1280x960 with my old USB2 cam and reaches about 200fps for small regions of interest. Currently there is no support for the raspberry (because I have none), but with your help I could add it in some minutes. Windows *should* work, but I haven"t tested it properly. If you are willing to invest a few hours, feel free to test :)

User avatar
Support2@ZWO
Posts: 668
Joined: Thu Feb 09, 2017 4:58 am

Re: Video Stream

Post by Support2@ZWO » Fri Apr 03, 2020 6:27 am

Just use the ASIGetVideoData to get the video stream. I think it is easy.
Then use openCV, it support to add to video stream to a new stream and show it in one window.
The attachment is a small example of my search, using opencv to display two videos in the same window. Hope it is useful.
Thanks
Chad
Attachments
test.cpp
(2.9 KiB) Downloaded 48 times
ZWO Driver Engineer
Location:lon=120.6 lat=31.3
SuZhou China

Chopperkirks
Posts: 6
Joined: Thu Mar 26, 2020 10:29 am

Re: Video Stream

Post by Chopperkirks » Fri Apr 03, 2020 8:52 am

Thank you for your response. The part I am a bit confused about is between using ASIGetVideoData and publishing it to a stream.

From what I Understand of the example you sent me the two video files are read in here

CvCapture * pCapture1 = cvCaptureFromAVI ("First video address");
CvCapture * pCapture2 = cvCaptureFromAVI ("second video address");

How do I get from ASIGetVideoData to a video address. Do I have to temporarily save it to a file or can I use the pBuffer instead of the video address?

Chopperkirks
Posts: 6
Joined: Thu Mar 26, 2020 10:29 am

Re: Video Stream

Post by Chopperkirks » Sun Apr 05, 2020 11:09 am

Have got it working quite easily using opencv. By creating a Mat object and running the ASIGetVideoData in a loop with the wait time in the exposure loop set to ASI_EXPOSURE * 2 you can get a live feed in a named window using imshow. The basic code is as follows for a single camera (this is a mono camera so the mat type is set to be a 16bit single channel, for a color use CV_8UC3).

Mat frame(Height,Width, CV_16UC1);
long iBuffSize = frame.total() * frame.elemSize();
int iWaitms = ASI_EXPOSURE*2;
bool cap = true;
while (cap)
{
ASIGetVideoData(camID, frame.data, iBuffSize, iWaitms);
namedWindow("video", WINDOW_GUI_EXPANDED);
imshow("video", frame);

waitKey(10);

}

User avatar
Support2@ZWO
Posts: 668
Joined: Thu Feb 09, 2017 4:58 am

Re: Video Stream

Post by Support2@ZWO » Tue Apr 07, 2020 1:55 am

Yes, you are right, it is not complicated.
All videos are composed of continuous single-frame images.
So if you can get a continuous single frame images, then you will get the video stream.
Thanks
Chad
ZWO Driver Engineer
Location:lon=120.6 lat=31.3
SuZhou China

Post Reply