影像截取VideoBuffer用Halcon處理問題!! |
|
mason17776
一般會員 發表:2 回覆:5 積分:1 註冊:2006-08-21 發送簡訊給我 |
|
leesy
一般會員 發表:0 回覆:6 積分:1 註冊:2005-11-10 發送簡訊給我 |
HALCON 7.1X
使用GenImageInterleaved Option Explicit Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long Private Type BITMAP bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer bmBits As Long End Type Private Sub Command1_Click() Dim hBitmap As Long Dim res As Long Dim bmp As BITMAP Dim byteAry() As Byte Dim totbyte As Long Dim pic As StdPicture Dim img As HImageX Picture1.AutoRedraw = True Picture1.Cls Picture1.Picture = Nothing Picture1.Print Time Picture1.Picture = Picture1.Image Set pic = Picture1.Picture hBitmap = pic.Handle res = GetObject(hBitmap, Len(bmp), bmp) '取得BitMap的結構 totbyte = bmp.bmWidthBytes * bmp.bmHeight '總共要多少個Byte來存圖 ReDim byteAry(totbyte - 1) '將該圖全放進ByteAry中 res = GetBitmapBits(hBitmap, totbyte, byteAry(0)) Set img = New HImageX img.GenImageInterleaved VarPtr(byteAry(0)), "bgrx", bmp.bmWidth, bmp.bmHeight, 0, "byte", bmp.bmWidth, bmp.bmHeight, 0, 0, -1, 0 HWindowXCtrl1.HalconWindow.SetPart 0, 0, bmp.bmHeight - 1, bmp.bmWidth - 1 HWindowXCtrl1.HalconWindow.DispObj img End Sub |
mason17776
一般會員 發表:2 回覆:5 積分:1 註冊:2006-08-21 發送簡訊給我 |
|
leesy
一般會員 發表:0 回覆:6 積分:1 註冊:2005-11-10 發送簡訊給我 |
Option Explicit
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Private Declare Function GetTickCount Lib "kernel32" () As Long Private Type BITMAP bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer bmBits As Long End Type Private Sub Command2_Click() Dim hBitmap As Long Dim res As Long Dim bmp As BITMAP Dim byteAry() As Byte Dim totbyte As Long Dim pic As StdPicture Dim img As HImageX Dim bgr() As Byte Dim i As Long, j As Long Dim t As Long Dim pt As Long 'Halcon 6.0X~7.0X '模擬BGRA 32bit t = GetTickCount() Randomize Picture1.AutoRedraw = True Set Picture1.Picture = Nothing Picture1.Cls Picture1.Print Timer * Rnd Set Picture1.Picture = Picture1.Image Set pic = Picture1.Picture hBitmap = pic.Handle res = GetObject(hBitmap, Len(bmp), bmp) '取得BitMap的結構 totbyte = bmp.bmWidthBytes * bmp.bmHeight '總共要多少個Byte來存圖 ReDim byteAry(totbyte - 1) ReDim bgr(bmp.bmWidth * bmp.bmHeight - 1, 2) '將該圖全放進ByteAry中 res = GetBitmapBits(hBitmap, totbyte, byteAry(0)) '實際BGRA 32bit 'ReDim byteAry(Width * Height * 4 - 1) 'ReDim bgr(Width * Height - 1, 2) 'pt為VideoBuffer的指標位置 'CopyMemory byteAry(0), ByVal pt, Width * Height * 4 j = 0 For i = 0 To totbyte - 1 Step 4 bgr(j, 0) = byteAry(i) bgr(j, 1) = byteAry(i 1) bgr(j, 2) = byteAry(i 2) j = j 1 Next i Set img = New HImageX img.GenImage3 "byte", bmp.bmWidth, bmp.bmHeight, VarPtr(bgr(0, 2)), VarPtr(bgr(0, 1)), VarPtr(bgr(0, 0)) HWindowXCtrl1.HalconWindow.SetPart 0, 0, bmp.bmHeight - 1, bmp.bmWidth - 1 HWindowXCtrl1.HalconWindow.DispObj img Me.Caption = CStr((GetTickCount() - t) / 1000) Set img = Nothing End Sub |
mason17776
一般會員 發表:2 回覆:5 積分:1 註冊:2006-08-21 發送簡訊給我 |
|
leesy
一般會員 發表:0 回覆:6 積分:1 註冊:2005-11-10 發送簡訊給我 |
因為模擬BGRA 32bit,為了取得影像資料,才使用 BitMap,正常BitMap是不需要得.
'底下程式碼,應該是你所需要得 ''實際BGRA 32bit ReDim byteAry(mWidth * mHeight * 4 - 1) As Byte ReDim bgr(mWidth * mHeight - 1, 2) As Byte 'pt為VideoBuffer的指標位置 CopyMemory byteAry(0), ByVal pt, mWidth * mHeight * 4 j = 0 For i = 0 To totbyte - 1 Step 4 bgr(j, 0) = byteAry(i) bgr(j, 1) = byteAry(i 1) bgr(j, 2) = byteAry(i 2) j = j 1 Next i Set img = New HImageX img.GenImage3 "byte", mWidth, mHeight, VarPtr(bgr(0, 2)), VarPtr(bgr(0, 1)), VarPtr(bgr(0, 0)) HWindowXCtrl1.HalconWindow.SetPart 0, 0, mHeight - 1, mWidth - 1 HWindowXCtrl1.HalconWindow.DispObj img Set img = Nothing |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |