全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:3872
推到 Plurk!
推到 Facebook!

影像截取VideoBuffer用Halcon處理問題!!

 
mason17776
一般會員


發表:2
回覆:5
積分:1
註冊:2006-08-21

發送簡訊給我
#1 引用回覆 回覆 發表時間:2006-11-27 15:07:15 IP:220.130.xxx.xxx 訂閱
請問:
我已使用影像截取卡API知道VideoBuffer的指標位置在哪
使用Halcon Function Gen_image1可以正常輸出黑白影像至Halcon Window
但假如把影像輸入格式改成32bit 彩色輸入
該使用哪各Function才能得到正常的彩色影像呢...還是需要怎樣處理呢...THX
好像要先把Buffer內的RGB值取出的樣子....不知道有沒有人會VB取buffer內RGB值的方法
我是先使用VB...等OK後會轉至Delphi...



leesy
一般會員


發表:0
回覆:6
積分:1
註冊:2005-11-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2006-12-11 02:47:00 IP:59.127.xxx.xxx 未訂閱
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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2006-12-14 15:32:59 IP:220.135.xxx.xxx 訂閱
謝謝你^^
記的上次也是你的幫忙回答
我用的是7.0版的好像沒有你說的GenImageInterleaved
還是7.0的有別的方式嗎
不管怎樣還是謝謝^^
leesy
一般會員


發表:0
回覆:6
積分:1
註冊:2005-11-10

發送簡訊給我
#4 引用回覆 回覆 發表時間:2006-12-17 00:06:24 IP:59.127.xxx.xxx 未訂閱
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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2006-12-18 20:22:10 IP:220.135.xxx.xxx 訂閱
感謝...我會試看看的
VB原來要先用BITMAP處理
Delphi不知道有沒有BITMAP!!
等出差回去就先試試看
謝謝你的大力幫忙阿.....
leesy
一般會員


發表:0
回覆:6
積分:1
註冊:2005-11-10

發送簡訊給我
#6 引用回覆 回覆 發表時間:2006-12-20 01:41:42 IP:59.127.xxx.xxx 未訂閱
因為模擬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

系統時間:2024-03-29 2:44:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!