Some Basic Help Please (ASI SDK, OpenCV)

any question related to our SDK and driver

Moderators: yang, Support@ZWO

Post Reply
jacob.m
Posts: 10
Joined: Mon Jun 18, 2018 8:01 pm

Some Basic Help Please (ASI SDK, OpenCV)

Post by jacob.m » Sun Mar 08, 2020 5:31 pm

Hello,

I am in need of some help. The task I am trying to accomplish for my project is, seemingly, simple:

What I have:
A ZWO ASI290mm
A Raspberry Pi 3b+, with the ZWO ASI SDK downloaded and installed, and the latest version of OpenCV installed.

What I am trying to do:
The task I want to do is simple: take a (or several in a loop) full resolution raw exposure (of type RAW16) with the ASI290mm and store it as a 16 bit tiff. For this application, I don't care about seeing the result, having a reduced ROI, video capture, or anything of that nature. I don't even particularly care about user input to set such things as image type, etc, these can be statically set in the program. I just want to capture and store the frame, as described.

What I have tried:
I have looked at the demo code that comes with the SDK, and have taken one of those programs and sort of chopped it up to reduce it to what I want to do above. I have some problem and concerns, however. The call to save an image, when uncommented in the demo program, reads like this:

Code: Select all

if(bsave)
	cvSaveImage("saveImage.jpg", pRgb);
	bSave = false;
Where pRgb is defined earlier as:

Code: Select all

IplImage *pRgb;
And this seems to be the failing point in compiling this program. The error output is this:

Code: Select all

error: 'cvSaveImage' was not declared in this scope
After some digging, it seems that the whole demo program is using the old C API for OpenCV (old as of OpenCV 1.x, we are now on OpenCV 4.x), which includes the whole IplImage and cvSaveImage stuff, so every troubleshooting search I have done has basically resulted in people saying "use the new C++ API which takes care of garbage collection using Mat instead of IplImage and imwrite() instead of cvSaveImage, etc".

So I've come to the conclusion that I have to redo things in the new C++ way. However, I'm not sure how. I assume I need to declare a Mat, something like

Code: Select all

Mat img(height,width, CV_16UC1);
I see that in the suggested call sequence, there is ASIStartExposure, ASIGetExpStatus, and finally if ASI_EXP_SUCCESS then ASIGetDataAfterExp. That sequence makes sense to me. But I'm not sure how to go from that sequence to implementing it such that the data is captured by OpenCV and written as a tiff.

Could someone kindly help me?

Thanks,
Jacob

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

Re: Some Basic Help Please (ASI SDK, OpenCV)

Post by Support2@ZWO » Mon Mar 09, 2020 1:46 am

Hi Jacob,
You can download our Linux SDK, there is a demo inside it, You can follow it.
Thanks
Chad
ZWO Driver Engineer
Location:lon=120.6 lat=31.3
SuZhou China

jacob.m
Posts: 10
Joined: Mon Jun 18, 2018 8:01 pm

Re: Some Basic Help Please (ASI SDK, OpenCV)

Post by jacob.m » Mon Mar 09, 2020 12:16 pm

Chad,

In case it wasn't clear, I have downloaded the Linux SDK, and am trying to follow the demo code. Please see my original post for the error I get upon trying to compile it.

Again, allow me to reiterate my concerns with the demo code:
1. It seems to use the outdated C API of OpenCV
2. It doesn't compile, where the problem comes at the "cvSaveImage()" call

At this point, I don't even particularly care whether is it uses the C or C++ standard of OpenCV, as long as I can get something (anything) to work.

Therefore, I would be extremely grateful if I could get some help getting me to the point where I can capture and store a 16 bit tiff in C++, or at least get rid of the compiler error in the code as is.

Thanks,
Jacob

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

Re: Some Basic Help Please (ASI SDK, OpenCV)

Post by Support2@ZWO » Tue Mar 10, 2020 3:25 am

Hi Jacob,
Try this:
IplImage* ipl_img = cvLoadImage("samples.bmp");;

Mat mat_img;
mat_img = Mat(ipl_img);
Or
cv::Mat mImage;
cv::Mat mtx(iplImage);
mImage = mtx.clone();
Thanks
Chad
ZWO Driver Engineer
Location:lon=120.6 lat=31.3
SuZhou China

jacob.m
Posts: 10
Joined: Mon Jun 18, 2018 8:01 pm

Re: Some Basic Help Please (ASI SDK, OpenCV)

Post by jacob.m » Wed Mar 11, 2020 8:30 pm

Chad,

I'm afraid I don't understand your response.
Try this:
IplImage* ipl_img = cvLoadImage("samples.bmp");;
I'm not sure how this helps... I'm not trying to open an existing file, nor am I interested in using bmp.
Mat mat_img;
mat_img = Mat(ipl_img);
Or
cv::Mat mImage;
cv::Mat mtx(iplImage);
mImage = mtx.clone();
Again, I'm not sure how this helps my problem.

Can you please explain the steps to me: how to I go from an exposure on the ASI290mm to a 16bit tiff?

Thanks,
Jacob

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

Re: Some Basic Help Please (ASI SDK, OpenCV)

Post by Support2@ZWO » Thu Mar 12, 2020 6:28 am

Hi Jacob,
I think you should search for the definitions of these classes or structures yourself。
For IplImage, there is an item named (char *) imageData in this structure, you can use it as the parameter of ASIGetDataAfterExp.
After that, If you really need Mat, you can use my example to convert this IplImage into Mat.
If you only need tiff, you should follow the documention of tiff to save this image Data into tiff file.
Thanks
Chad
ZWO Driver Engineer
Location:lon=120.6 lat=31.3
SuZhou China

jacob.m
Posts: 10
Joined: Mon Jun 18, 2018 8:01 pm

Re: Some Basic Help Please (ASI SDK, OpenCV)

Post by jacob.m » Fri Mar 27, 2020 3:31 pm

Hi,

It has been suggested to me that I probably don't even need OpenCV, that I can use something like libtiff to save the image. This seems like a logical way to go. How do I go from the call of ASIGetDataAfterExp() to saving an image as a tiff in this way?

Thanks,
Jacob

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

Re: Some Basic Help Please (ASI SDK, OpenCV)

Post by Support2@ZWO » Fri Apr 03, 2020 3:53 am

Hi Jacob,
OpenCV does not affect saving the image to tiff.
For us, when you call ASIGetDataAfterExp(), then the buffer (point by the 2nd parameter) will be fixed with the data. You can use these data to fix the buffer of OpenCV, also you could use it to fix a tiff file.
Now your problem is that, you do not know how to use the data. I think you should go to the forum of OpenCV or TIFF for help.
Thanks
Chad
ZWO Driver Engineer
Location:lon=120.6 lat=31.3
SuZhou China

Post Reply