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

矩形比對

尚未結案
yplin
一般會員


發表:9
回覆:16
積分:5
註冊:2004-08-07

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-02-03 14:03:53 IP:140.112.xxx.xxx 未訂閱
大家好: 如果我想達到在序列影像中做矩形比對的目的,不知道要以何種方式開始著手比較適合,不知各位有無類似的經驗可以分享一下心得,謝謝~
1666362
初階會員


發表:66
回覆:124
積分:43
註冊:2004-07-07

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-02-03 16:46:43 IP:61.222.xxx.xxx 未訂閱
可以用NCC的方式 下面程式碼 您參考看看    
 
int M, N, K, L;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
   bmp1=new Graphics::TBitmap();
   bmp2=new Graphics::TBitmap();
   bmp2->PixelFormat=pf24bit;
   bmp2->Assign(Image2->Picture);
   bmp2->Width=Image2->Width;
   bmp2->Height=Image2->Height;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if (OpenPictureDialog1->Execute())
  {
    Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);
    bmp1->Assign(Image1->Picture);
    bmp1->PixelFormat=pf24bit;
    bmp1->Width=Image1->Width;
    bmp1->Height=Image1->Height;
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
   M=Image1->Height;
   N=Image1->Width;
   K=Image2->Height;
   L=Image2->Width;       double w=0;
   static double G[48][48];       byte *ptr;
   for(int y=0; yScanLine[y];
      for(int x=0; xScanLine[y];
      for(int x=0; x=max)
            max=C[i][j];             a=b=c=0;
      }
   }
   Memo1->Lines->Add("收尋完成!!");
   Memo1->Lines->Add("相關係數=");
   Memo1->Lines->Add(max);       for(int j=0; j<240-48; j++)
      for(int i=0; i<320-48; i++)
         if(C[i][j] >= 0.9)
         {
         Image1->Canvas->Brush->Style=bsClear;
         Image1->Canvas->Pen->Color=clRed;
         Image1->Canvas->Rectangle(i,j,i+48,j+48);
         }    }
//---------------------------------------------------------------------------
發表人 - 1666362 於 2005/02/03 21:55:49 發表人 - 1666362 於 2005/02/03 21:56:32
yplin
一般會員


發表:9
回覆:16
積分:5
註冊:2004-08-07

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-02-04 12:37:35 IP:140.112.xxx.xxx 未訂閱
謝謝你的回覆~ 由於我的目的是從動態影像中做矩行框的定位,相反的是webcam是在移動的狀況下,而矩行框是固定的。所以碰到的問題會是因為webcam的移動而產生矩行框大小的變動,甚至有點扭曲的現象,沒辦法以單一的template來做比對。 不知你還有沒有其他的建議呢? 謝謝~ 發表人 - yplin 於 2005/02/04 12:39:33
hopgins
一般會員


發表:4
回覆:3
積分:1
註冊:2006-12-20

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-11-13 12:12:46 IP:59.127.xxx.xxx 訂閱
您好!!我trace過您的程式有些問題,不知道有人能夠幫忙一下嘛??
我的templete的大小是96*96
待測 image是640*480
我所trace的code如下,當成是跑到下面要估算相關度時卻會出現 DOMAIN error。
不知道到底是哪出錯!!我覺得這隻code應該沒問題!!想請有心人幫忙解決 謝謝


void __fastcall TForm1::Button2Click(TObject *Sender)
{
Graphics::TBitmap *bmp1=new Graphics::TBitmap();
Graphics::TBitmap *bmp2=new Graphics::TBitmap();
bmp2->PixelFormat=pf24bit;
bmp2->Assign(Image2->Picture->Bitmap);
bmp2->Width=Image2->Width;
bmp2->Height=Image2->Height;
bmp1->Assign(Image1->Picture->Bitmap);
bmp1->PixelFormat=pf24bit;
bmp1->Width=Image1->Width;
bmp1->Height=Image1->Height;

M=Image1->Height;
N=Image1->Width;
K=Image2->Height;
L=Image2->Width;
double w=0;
static double G[96][96];
Byte *ptr;
for(int y=0; yHeight;y )
{
ptr = (Byte*)bmp2->ScanLine[y];
for(int x=0; x {
w = (double)(ptr[x] ptr[x 1] ptr[x 2])/3;
G[x/3][y] = (double)(ptr[x] ptr[x 1] ptr[x 2])/3;
}
}
w /= ( K*L );
static double F[640][480];
static double C[640-96][480-96]={0};

for(int y=0; y {
ptr = (Byte*)bmp1->ScanLine[y];
for(int x=0; x F[x/3][y] = (double)(ptr[x] ptr[x 1] ptr[x 2])/3;
}
double a=0;
double b=0;
double c=0;
double f=0;

double max=0;
for(int j=0; j {
for(int i=0; i {
f=0;
for(int y=j; y<(j K); y )
{
for(int x=i; x<(i L); x )
f =F[x][y];
f/=(K*L);
}
for(int y=-48;y<=48;y )
{
for(int x=-48;x<=48;x )
{
a = (G[x][y] - w)*(F[x i][y j] - f);
b = (G[x][y] - w)*(G[x][y] - w);
c = (F[x i][y j] - f)*(F[x i][y j] - f);
}
}
Image1->Canvas->Pen->Color=clRed;
Image1->Canvas->Rectangle(i,j,i 96,j 96);
}
}
lichart
一般會員


發表:0
回覆:4
積分:5
註冊:2005-09-01

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-12-31 20:40:23 IP:220.143.xxx.xxx 訂閱
在作sqrt前先作簡單非負/零判斷
例如 (精確度自訂):
b = (b<0.0001)? 0.01: sqrt(b);
c = (c<0.0001)? 0.01: sqrt(c);
C[i][j] = a/(b c);
jenglin
一般會員


發表:45
回覆:32
積分:15
註冊:2006-10-08

發送簡訊給我
#6 引用回覆 回覆 發表時間:2008-02-16 14:25:19 IP:163.18.xxx.xxx 訂閱
for(int j=0; j    {
for(int i=0; i {
請問這2行是不是有少什麼?
編輯記錄
jenglin 重新編輯於 2008-02-16 21:16:36, 註解 無‧
yulong375
一般會員


發表:2
回覆:22
積分:19
註冊:2007-03-15

發送簡訊給我
#7 引用回覆 回覆 發表時間:2008-03-02 22:57:25 IP:140.128.xxx.xxx 訂閱
要在動態影像辨識矩行框,那你必須要讓影像知道「矩形」的定義。
換言之,就人的角度,雖然我們肉眼看影像知道什麼是矩形,
但就程式的角度,你要如何讓它知道這張影中有「矩形」的存在呢?

給你幾個方向:二值化 -> 邊緣化 -> 霍式轉換 -> 最小平方法 -> 找轉折點 -> 辨識矩形
------
我還是很新的新手,如果回答的太笨拙還請各位多多包含!!
系統時間:2024-03-29 19:01:25
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!