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

將連續影像對同一張影像做相減show到Image上

尚未結案
MemoryQ
一般會員


發表:4
回覆:7
積分:2
註冊:2005-10-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-11-10 10:53:51 IP:163.28.xxx.xxx 未訂閱
大家好, 想向大家請教 我之前在做連續影像相減可是讓前後兩張的影像丟到不同buffer的問題一直無法解決, 所以我想先拍下一張影像存檔, 然後再將連續影像都對拍下來的那一張做相減再show出來, 我想先試試這個再回去做連續影像相減, 可是我要執行時出現了 "Debugger Exception Notification" 這個視窗, 上面寫著 "Project Project1.exe raised exception class EAccess Violation with message 'Access violation at address 00401F30 in module 'Project1.exe'. Write of address 00000000'. Process stopped Use Step or Run to continue." 我不知道是哪裡出了問題, 以下是我的程式     
//---------------------------------------------------------------------------    #include 
#pragma hdrstop    #include "Unit1.h"    #include 
#include <math.h>
#include 
#include 
#include     #define col 320
#define row 240    unsigned char  *image;
unsigned char  *gray1;
unsigned char  *gray2;
unsigned char  *subtraction;    //---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "EzCapCamera"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button1Click(TObject *Sender)
{
 EzCapCamera1->CameraDisplay();   //開啟攝影機功能     if (!(image=new unsigned char [3*240*320 1])||
     !(gray1=new unsigned char [240*320 1])||
     !(gray2=new unsigned char [240*320 1])||
     !(subtraction=new unsigned char [240*320 1])
    )
 {}
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button2Click(TObject *Sender)
{
 EzCapCamera1->CapBmpPic("1.bmp"); //儲存圖檔     FILE *fin;
 int buff1=0;
 int i;     if((fin=fopen("1.bmp","rb"))== NULL)
 {}
 
 fread(image,240*320,3,fin);
 fclose(fin);     buff1=0;
 for(i=0;i<3*240*320;i=i 3)
 {
  gray1[buff1]=0.299*image[i 2] 0.587*image[i 1] 0.114*image[i];
  buff1  ;
 }    }
//---------------------------------------------------------------------------    void __fastcall TForm1::Button3Click(TObject *Sender)
{
 delete [] image;
 delete [] gray1;
 delete [] gray2;
 delete [] subtraction;     EzCapCamera1->CameraClose();  //關閉攝影機功能
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
 EzCapCamera1->CapBmpPic("2.bmp"); //儲存圖檔        
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
 Image1->Picture->LoadFromFile("2.bmp"); //載入圖檔
 if (Image1->Picture->Bitmap->Empty==true)
 {
  ShowMessage("請載入圖檔!!");
 }
 Graphics::TBitmap *Bmp = new Graphics::TBitmap();
 Byte *ptr;
 int Width,Height,r,g,b;
 int i,j;
 Bmp->Assign(Image1->Picture->Bitmap);
 for(j=0;jHeight;j  )
 {
  ptr = (Byte *)Bmp->ScanLine[j];
  for(i=0;iWidth;i  )
  {
   b=ptr[i*3];
   g=ptr[i*3 1];
   r=ptr[i*3 2];
   gray2[j*col i]=0.299*r  0.587*g 0.114*b; 
  }
 }     
 for(i=0;i=70)
    subtraction[i]=0;
  else
    subtraction[i]=255;
 }     for(j=0;jHeight;j  )
 {
   ptr = (Byte *)Bmp->ScanLine[j];
   for(i=0;iWidth;i  )
   {
    ptr[i*3]=subtraction[j*col i];
    ptr[i*3 1]=subtraction[j*col i];
    ptr[i*3 2]=subtraction[j*col i];
   }
 }    Image2->Picture->Assign(Bmp);    }
//---------------------------------------------------------------------------     
麻煩請大家幫我看看, 謝謝大家
justdo
高階會員


發表:2
回覆:359
積分:222
註冊:2004-08-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-11-10 23:07:46 IP:221.169.xxx.xxx 未訂閱
 if((fin=fopen("1.bmp","rb"))== NULL)
 {}
 
 fread(image,240*320,3,fin);
 fclose(fin);
bmp檔不是這樣讀的,他有檔頭資料,也有自己的格式描述 另外,是執行到哪一行發生錯誤的?
MemoryQ
一般會員


發表:4
回覆:7
積分:2
註冊:2005-10-17

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-11-11 14:43:34 IP:163.28.xxx.xxx 未訂閱
justdo您好 很感謝您的回答, 那請問您bmp檔要如何讀檔呢?(我要讀到image這個buffer裡面去) 另外我在run程式的時候可以過, 是run完出現Form1時突然跳出"Debugger Exception Notification"這個視窗的, 可以麻煩您指導一下嗎? 非常感謝您^^" 發表人 - MemoryQ 於 2005/11/11 14:48:09
justdo
高階會員


發表:2
回覆:359
積分:222
註冊:2004-08-17

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-11-13 22:24:59 IP:221.169.xxx.xxx 未訂閱
引言: justdo您好 很感謝您的回答, 那請問您bmp檔要如何讀檔呢?(我要讀到image這個buffer裡面去)
用 "讀bmp" 關鍵字搜尋一下本站文章,即可找到參考文章
引言: 另外我在run程式的時候可以過, 是run完出現Form1時突然跳出"Debugger Exception Notification"這個視窗的, 可以麻煩您指導一下嗎? 非常感謝您^^"
因為我沒有webcam所以無法測試你的程式 請用F7或F8指令一行行的執行,看跑到哪一行才出問題的
系統時間:2024-05-12 0:01:04
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!