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

買了一台攝影機,有廠商附的demo code,但還是不會取像...

尚未結案
shiuan0610
一般會員


發表:15
回覆:13
積分:5
註冊:2007-05-08

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-06-24 22:56:26 IP:114.38.xxx.xxx 訂閱
各位先進大家好,事情是這樣的
我買了一台攝影機,廠商也附了BCB的demo code給我(廠商工程師不會BCB,他們前人寫的)
老實說我看不懂它程式運作的機制,希望能先取得影像資料來處理就好

它執行後是把影像丟到ScrollBox1顯示
但我不知道要如何取得上面的影像資料
我把主程式貼在最下面,我也不知道這樣的資訊是不是足夠讓有經驗的先進可以判斷如何做
我想著若能把影像資料丟到Image元件裡,就等於我可以取得影像資料來做處理了

在FormShow裡面有一行:
m_hwnd = (int)ScrollBox1->Handle;
我原以為改成下面這行就可以了
m_hwnd = (int)Image1->Picture->Bitmap->Canvas->Handle;
但事實證明不行

有人可以給我建議嗎??
感激不盡~~

[code cpp]
//---------------------------------------------------------------------------
#include
#pragma hdrstop

#include "Unit1.h"
#include "UEye.h"
#include "Msg_Hook.h"
#include "uEye_tools.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int m_hu,m_hwnd;
int m_pcMem,m_nMemID;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __stdcall AfterMessage(long id, long hWnd, long uMsg, long wParam, long lParam, long *retValue)
{
if (id == 0 && hWnd == (long)m_hwnd)
{
switch (uMsg) {
case IS_UEYE_MESSAGE :
switch (wParam) {
case IS_DEVICE_REMOVED :
Beep(400, 50);
break;
case IS_DEVICE_RECONNECTED :
Beep(400, 50);
break;
case IS_FRAME :
if (m_pcMem != 0 && m_hu != -1)
{
Form1->Label1->Caption = "Message:Frame--" TimeToStr(Time());
iss_RenderBitmap(m_hu, m_nMemID, m_hwnd, IS_RENDER_FIT_TO_WINDOW);
}
break;
}
break;
}
}
}

//---------------------------------------------------------------------------
int __fastcall TForm1::InitCamera(int nId, int mhwnd)
{
int nRet,hu;

nRet = IS_CANT_OPEN_DEVICE;
hu = nId;
if (m_hu == -1)
{
nRet = iss_InitCamera(&hu, mhwnd);
if (nRet == IS_SUCCESS)
{
m_hu = hu;
m_hwnd = mhwnd;
iss_EnableAutoExit(m_hu, IS_DISABLE_AUTO_EXIT);
}
}
return nRet;
}

int __fastcall TForm1::ExitCamera()
{
int nRet = IS_CANT_CLOSE_DEVICE;

if(m_hu != -1)
{
nRet = iss_ExitCamera(m_hu);
m_hu = -1;
}
return nRet;
}

bool __fastcall TForm1::OpenCamera()
{
SENSORINFO msensorInfo;

iss_EnableMessage(m_hu, IS_FRAME, m_hwnd);
iss_ExitCamera(m_hu);

m_Ret = InitCamera(0, m_hwnd);
if (m_Ret == IS_SUCCESS)
{
iss_GetSensorInfo(m_hu, &msensorInfo);
//iss_GetColorDepth(m_hu, m_nBitsPerPixel, m_nColorMode);
//iss_SetColorMode(m_hu, m_nColorMode);
//m_nBitsPerPixel = 8;
//iss_SetColorMode(m_hu, IS_SET_CM_Y8);
//if Color
m_nBitsPerPixel = 32;
iss_SetColorMode(m_hu, IS_SET_CM_RGB32);

iss_SetDisplayMode(m_hu, IS_SET_DM_DIB);
m_nSizeX = msensorInfo.nMaxWidth;
m_nSizeY = msensorInfo.nMaxHeight;
m_nSizeX = m_nSizeX & 0xFFFC;
m_nSizeY = m_nSizeY & 0xFFFC;

iss_AllocImageMem(m_hu, m_nSizeX, m_nSizeY, m_nBitsPerPixel,(char **)&m_pcMem, &m_nMemID);
iss_SetImageMem(m_hu,(char *)m_pcMem, m_nMemID);
iss_SetImageSize(m_hu, m_nSizeX, m_nSizeY);
iss_SetWhiteBalance(m_hu, IS_SET_WB_AUTO_ENABLE);
iss_EnableMessage(m_hu, IS_DEVICE_REMOVED, m_hwnd);
iss_EnableMessage(m_hu, IS_DEVICE_RECONNECTED, m_hwnd);
iss_EnableMessage(m_hu, IS_FRAME, m_hwnd);
return true;
}
else
{
Application->MessageBox("No uEye camera could be opened !", "訊息", MB_OK);
return false;
}
}

void __fastcall TForm1::FormShow(TObject *Sender)
{
AnsiString FileName;

m_hu = -1;
m_hwnd = (int)ScrollBox1->Handle;
m_pcMem = 0;
Msg_Hook_Start(0,m_hwnd,0,int(AfterMessage));
if (OpenCamera())
{
mwidth = m_nSizeX;
mheight = m_nSizeY;
isavi_InitAVI(&nAviID, m_hu);
isavi_SetImageSize(nAviID, IS_AVI_CM_RGB32, mwidth, mheight, 0, 0, 0);
FileName = ExtractFilePath(Application->ExeName) "\\demo.avi";
isavi_OpenAVI(nAviID,FileName.c_str());
}
else
Button1->Enabled = false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if (m_pcMem != 0)
{
iss_RenderBitmap(m_hu, m_nMemID, m_hwnd, IS_RENDER_FIT_TO_WINDOW);
isavi_AddFrame(nAviID, (char *)m_pcMem);
this->Text = TimeToStr(Time()) "--" IntToStr(m_pcMem);
}
else
this->Text = TimeToStr(Time());
Application->ProcessMessages();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
Timer1->Enabled = false;
isavi_StopAVI(nAviID);
isavi_CloseAVI(nAviID);
isavi_ExitAVI(nAviID);
iss_EnableMessage(m_hu, IS_FRAME, m_hwnd);
iss_StopLiveVideo(m_hu, IS_FORCE_VIDEO_STOP);
if (m_pcMem != 0)
iss_FreeImageMem(m_hu,(char *)m_pcMem,m_nMemID);
ExitCamera();
Msg_Hook_Stop(0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (Button1->Caption == "Run")
{
Button1->Caption = "Stop";
iss_CaptureVideo(m_hu, IS_WAIT);
isavi_StartAVI(nAviID);
Timer1->Enabled = true;
}
else
{
Button1->Caption = "Run";
Timer1->Enabled = false;
isavi_StopAVI(nAviID);
iss_StopLiveVideo(m_hu, IS_FORCE_VIDEO_STOP);
}
}

//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
if (m_pcMem != 0 && m_hu != -1)
iss_RenderBitmap(m_hu, m_nMemID, m_hwnd, IS_RENDER_FIT_TO_WINDOW);
}
//---------------------------------------------------------------------------

[/code]

編輯記錄
shiuan0610 重新編輯於 2010-06-24 22:59:40, 註解 無‧
系統時間:2017-10-17 5:55:06
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!