Register    Login    Forum    Search    FAQ

Board index » Software » Windows




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post Posted: Sat Jun 03, 2017 6:16 am 
Offline

Joined: Sat May 06, 2017 6:22 am
Posts: 4
Hi, i tried to get the image from the camera but the image is incorrect.
I'm using ZWO ASI290MM.

Code:
cbStat[0] = false;
            zwoCam.StopVideoCapture();
            zwoCam.StartExposure(50, false);
            expPtr = Marshal.AllocHGlobal(bufferSize);
            zwoCam.GetExposureData(expPtr, bufferSize);
            expBuffer = new Byte[bufferSize];
            Marshal.Copy(expPtr, expBuffer, 0, bufferSize);
            Marshal.FreeHGlobal(expPtr);
            int col = imageSize.Width;
            int row = imageSize.Height;
            int stride = col;
            Bitmap im = new Bitmap(col, row, stride, System.Drawing.Imaging.PixelFormat.Format8bppIndexed, Marshal.UnsafeAddrOfPinnedArrayElement(expBuffer, 0));
            String dir = "D:\\captures\\" + String.Format("{0:ddMMM-hh-mm-ss-fff-tt}", DateTime.Now) + ".png";
            //save image to directory
            im.Save(dir, System.Drawing.Imaging.ImageFormat.Png);


I also tried the GetVideoData and the image isn't correct.
Attachment:
03Jun-02-13-17-977-PM.png
03Jun-02-13-17-977-PM.png [ 81.15 KiB | Viewed 430 times ]

I used Format8ppIndexed for this.
Code:
Bitmap im = new Bitmap(col, row, stride, System.Drawing.Imaging.PixelFormat.Format8bppIndexed,
Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0));


Attachment:
03Jun-02-23-17-809-PM.png
03Jun-02-23-17-809-PM.png [ 39.23 KiB | Viewed 428 times ]

I used Format1bppIndexed for this.

Its supposed to be a smooth white image according to SharpCap.

Please advice, thanks.


Top 
 Profile  
Reply with quote  
 Post Posted: Mon Jun 05, 2017 1:02 am 
Offline
Site Admin

Joined: Fri Jul 25, 2014 2:43 am
Posts: 188
if you use Format8bppIndexed, the image does not look like that in SharpCap, you can try to use other image format.
besides, in the second image you attached, I can see vertical line, but not with the first image, what is the difference when capturing these two images in setup?

_________________
ZWO software engineer
Location:lon=120.6 lat=31.3
SuZhou China


Top 
 Profile  
Reply with quote  
 Post Posted: Tue Jun 06, 2017 10:12 am 
Offline

Joined: Sat May 06, 2017 6:22 am
Posts: 4
Hi,

thanks for the reply. The second image attached uses Format1bppIndexed while the first image attached uses Format8bppIndexed. I'll try again and let you know if the problem persist.

Thanks!


Top 
 Profile  
Reply with quote  
 Post Posted: Wed Jun 07, 2017 1:18 am 
Offline
Site Admin

Joined: Fri Jul 25, 2014 2:43 am
Posts: 188
If you want to display captured data as normal color, you should use Format24bppRgb, and fill R G B bytes with correct value for each pixel, for RAW8, fill R G B with the same value

_________________
ZWO software engineer
Location:lon=120.6 lat=31.3
SuZhou China


Top 
 Profile  
Reply with quote  
 Post Posted: Sun Jun 11, 2017 5:24 am 
Offline

Joined: Sat May 06, 2017 6:22 am
Posts: 4
So for a RAW8, I used this:

Bitmap im = new Bitmap(col, row, stride, PixelFormat.Format24bppRgb, Marshal.UnsafeAddrOfPinnedArrayElement(lvBuffer, 0));

Correct?


Top 
 Profile  
Reply with quote  
 Post Posted: Mon Jun 12, 2017 12:51 am 
Offline
Site Admin

Joined: Fri Jul 25, 2014 2:43 am
Posts: 188
int IMAGE_WIDTH = SelectedCameraInThr.CaptureAreaInfo.Size.Width;
int IMAGE_HEIGHT = SelectedCameraInThr.CaptureAreaInfo.Size.Height;
int stride = IMAGE_WIDTH;
Bitmap b24bpp = new Bitmap(IMAGE_WIDTH, IMAGE_HEIGHT, PixelFormat.Format24bppRgb);
var rect = new Rectangle(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
var bitmapBytes = new byte[IMAGE_WIDTH * IMAGE_HEIGHT * 3];
var bmp = new Bitmap(pictureBox.Width, pictureBox.Height, PixelFormat.Format24bppRgb);
var graph = Graphics.FromImage(bmp);
float scale = (float)Math.Min(1.0 * pictureBox.Width / IMAGE_WIDTH, 1.0 * pictureBox.Height / IMAGE_HEIGHT);
var scaleWidth = (int)(IMAGE_WIDTH * scale);
var scaleHeight = (int)(IMAGE_HEIGHT * scale);
Rectangle PicRect = new Rectangle((pictureBox.Width - scaleWidth) / 2, (pictureBox.Height - scaleHeight) / 2, scaleWidth, scaleHeight);
while (bCapture )
{
exp = CamCtrl.Value/1000;
exp = exp > 200 ? 200 : exp;
if (SelectedCameraInThr.GetVideoData(dataPtr, bufferSize, exp))
{
Marshal.Copy(dataPtr, buffer, 0, bufferSize);

var bitmapData = b24bpp.LockBits(rect, ImageLockMode.WriteOnly, b24bpp.PixelFormat);
var numberOfBytes = bitmapData.Stride * IMAGE_HEIGHT;
var ptr = bitmapData.Scan0;
if(SelectedCameraInThr.CaptureAreaInfo.ImageType == ASICameraDll.ASI_IMG_TYPE.ASI_IMG_RAW8
|| SelectedCameraInThr.CaptureAreaInfo.ImageType == ASICameraDll.ASI_IMG_TYPE.ASI_IMG_Y8)
{
int j = 0;
foreach (byte i in buffer)
{
bitmapBytes[j++] = i;
bitmapBytes[j++] = i;
bitmapBytes[j++] = i;
}

Marshal.Copy(bitmapBytes, 0, ptr, bitmapBytes.Length);
}
else if (SelectedCameraInThr.CaptureAreaInfo.ImageType == ASICameraDll.ASI_IMG_TYPE.ASI_IMG_RGB24)
{
Marshal.Copy(buffer, 0, ptr, bitmapBytes.Length);
}
else
{
int i, j = 0, iLen = buffer.GetLength(0);
byte Temp8;
for (i = 1; i < iLen; i += 2)
{
Temp8 = buffer[i];
bitmapBytes[j++] = Temp8;
bitmapBytes[j++] = Temp8;
bitmapBytes[j++] = Temp8;
}

Marshal.Copy(bitmapBytes, 0, ptr, bitmapBytes.Length);
}



b24bpp.UnlockBits(bitmapData);

graph.DrawImage(b24bpp, PicRect);
pictureBox.Image = bmp;
}

}

_________________
ZWO software engineer
Location:lon=120.6 lat=31.3
SuZhou China


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 6 posts ] 

Board index » Software » Windows


Who is online

Users browsing this forum: No registered users and 2 guests

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: