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

如何到資料夾進行圖片比對

尚未結案
frankh
一般會員


發表:25
回覆:36
積分:12
註冊:2005-05-04

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-08-23 20:05:08 IP:218.165.xxx.xxx 未訂閱
參考前輩之前的文章http://delphi.ktop.com.tw/topic.php?topic_id=71977我已經做出用一張圖片跟其他圖片作pixel值差異,但是需要一個一個按所要比對的圖片。我想請問一下,能否直接在比對資料夾的圖檔,然後把pixel值差異最小的圖檔直接放入image裡??請問有什麼辦法?麻煩請各位前輩給予我指教..謝謝^^ 發表人 - frankh 於 2005/08/23 20:22:48
frankh
一般會員


發表:25
回覆:36
積分:12
註冊:2005-05-04

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-08-25 17:51:19 IP:218.165.xxx.xxx 未訂閱
請問各位大大..我該用什麼關鍵字去尋找關於這方面的文章??
justdo
高階會員


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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-08-25 19:12:56 IP:221.169.xxx.xxx 未訂閱
可以用FindFirst相關的指令去搜尋整個目錄底下有哪些檔案 然後一一載入來做圖片比較
poaivy
中階會員


發表:40
回覆:78
積分:53
註冊:2004-08-09

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-08-27 07:57:18 IP:128.95.xxx.xxx 未訂閱
TSearchRec sr;
  String path = 資料夾路徑;
  String mask = "*.bmp";
  int iAttributes = 0;
  iAttributes |= faArchive;
    if (FindFirst(path   mask, iAttributes, sr) == 0)
  {
    do
    {
      if ((sr.Attr & iAttributes) == sr.Attr)
      {
          Image1->Picture->LoadFormFile(path sr.Name);
     這裡可以做你想要的比對工作;
     做完順便記錄其值,直到整個資料夾比對結束找出差異最小的。          }
    } while (FindNext(sr) == 0);
    FindClose(sr);
  }
試看看吧
frankh
一般會員


發表:25
回覆:36
積分:12
註冊:2005-05-04

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-08-29 19:10:42 IP:218.165.xxx.xxx 未訂閱
poaivy您好: 我試過了..但有些不懂的地方..像我原本有按鈕建的原始碼是不是直接把它刪掉就可以了?還有一個地方是我不知道我的原始碼是否有錯..因為我一直run不出來...可以幫我看一下嗎?
void __fastcall TForm1::Button5Click(TObject *Sender)
{
  //Graphics::TBitmap *Bmp[0] = new Graphics::TBitmap();
  //Graphics::TBitmap *Bmp[1] = new Graphics::TBitmap();
  //Graphics::TBitmap *Bmp[2] = new Graphics::TBitmap();
  //Graphics::TBitmap *Bmp[3] = new Graphics::TBitmap();
  TSearchRec sr;
  String path = c:/test;
  String mask = "*.bmp";
  int iAttributes = 0;
  iAttributes |= faArchive;
    if (FindFirst(path   mask, iAttributes, sr) == 0)
  {
    do
    {
      if ((sr.Attr & iAttributes) == sr.Attr)
      {
          Image1->Picture->LoadFormFile(path sr.Name);
          Graphics::TBitmap *Bmp[4];      for(int i = 0; i < 4; i  )
        Bmp[i] = new Graphics::TBitmap();      Bmp[0]->Assign(Image1->Picture->Bitmap);
  Bmp[1]->Assign(Image2->Picture->Bitmap);
  Bmp[2]->Assign(Image3->Picture->Bitmap);
  Bmp[3]->Assign(Image4->Picture->Bitmap);
  Byte *ptr1,*ptr2,*ptr3,*ptr4;
  int temp[4];                  for (int i=0;iHeight;i  )/*取值相減*/
   {
    ptr1=(Byte *)Bmp[0]->ScanLine[i];
    ptr2=(Byte *)Bmp[1]->ScanLine[i];
    ptr3=(Byte *)Bmp[2]->ScanLine[i];
    ptr4=(Byte *)Bmp[3]->ScanLine[i];
    for(int j=0;jWidth;j  )
     {
      temp[1] =abs((int)ptr1[3*j]-(int)ptr2[3*j]);
      temp[2] =abs((int)ptr1[3*j]-(int)ptr3[3*j]);
      temp[3] =abs((int)ptr1[3*j]-(int)ptr4[3*j]);
     }
   }
   int record[4] = {0, 1, 2, 3};       int tp;   /*泡沫排序*/
   for(int x=0;x<4;x  )
   {
    for(int i=1;i<4;i  )
    {
     if(temp[i 1] < temp[i])
     {
       tp=temp[i];
       temp[i]=temp[i 1];
       temp[i 1]=tp;           tp = record[i];
       record[i] = record[i 1];
       record[i 1] = tp;         }
    }
   }
    Image5->Picture->Assign(Bmp[record[1]]);          }
    } while (FindNext(sr) == 0);
    FindClose(sr);
  }    }
發表人 - frankh 於 2005/08/29 19:11:19
frankh
一般會員


發表:25
回覆:36
積分:12
註冊:2005-05-04

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-08-31 22:10:21 IP:218.165.xxx.xxx 未訂閱
請問哪位大大可以幫我看一下我的程式碼哪裡有問題? 我已經測了兩天了...一直跑不出來.. 拜託各位大大...
系統時間:2024-05-02 16:08:31
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!