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

出現Scanline out of range該如何解決

尚未結案
wbs173
一般會員


發表:12
回覆:26
積分:7
註冊:2005-03-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-04-06 21:12:01 IP:219.80.xxx.xxx 未訂閱
我在我的Timer裡面加入了以下的程式碼 但在compile時卻出現了Scanline out of range這個警告訊號 雖然跳過可以用 但是我想把她解決 我爬過了許多相關的文章 但卻還是不能解決 請會的高手幫個忙 程式有點長 麻煩多費心了 感激不盡~! void __fastcall TForm1::Timer3Timer(TObject *Sender) { // 統計水平與垂直方向的投影量 long ProjectV[320] = {0}; long ProjectH[240] = {0}; long Vmax = 0, Hmax = 0; Byte *ptr; StringGrid1->Cells[0][1]="垂直"; StringGrid1->Cells[0][2]="水平"; Image3->Canvas->Brush->Color = clWhite; Image3->Canvas->FillRect(TRect(0,0,Image3->Width,Image3->Height)); Image4->Canvas->Brush->Color = clWhite; Image4->Canvas->FillRect(TRect(0,0,Image4->Width,Image4->Height)); for(int row = 0; row < 240; row ) { ptr = (Byte *)Image2->Picture->Bitmap->ScanLine[row]; for(int col = 0; col < 320; col ) { if(col == 0) StringGrid1->Cells[0][col]="行(列)數";//設定StringGrid中最左上角那一小格的資訊 else StringGrid1->Cells[col][0]=IntToStr(col);//col header的值 if(ptr[col*3] == 0) // 黑點 { ProjectV[col] ; // 垂直方向投影的數量 1 ProjectH[row] ; // 水平方向投影的數量 1 if(ProjectV[col] > Vmax) Vmax = ProjectV[col]; // 統計垂直投影最大值 if(ProjectH[row] > Hmax) Hmax = ProjectH[row]; // 統計水平投影最大值 } } } // 畫出水平方向投影 Image3->Canvas->Pen->Color = clBlack; for(int row = 1; row <= 240; row ) { StringGrid1->Cells[row][2]=IntToStr(ProjectH[row]);//輸出水平方向的加總值 Image3->Canvas->MoveTo(Image3->Width, row); Image3->Canvas->LineTo(Image3->Width * (1.0 - (double)ProjectH[row] / (double)Hmax), row); } // 畫出垂直方向投影 Image4->Canvas->Pen->Color = clBlack; for(int col = 1; col <= 320; col ) { StringGrid1->Cells[col][1]=IntToStr(ProjectV[col]);//輸出垂直方向的加總值 Image4->Canvas->MoveTo(col, Image4->Height); Image4->Canvas->LineTo(col, Image4->Height * (1.0 - (double)ProjectV[col] / (double)Vmax)); }
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-04-06 22:12:00 IP:218.168.xxx.xxx 未訂閱
您好: po程式碼的方式請參考版規說明,煩請修改謝謝您的配合    先將Image2的AutoSize設為true看看
RedSnow
版主


發表:79
回覆:1322
積分:845
註冊:2003-12-15

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-04-06 22:29:39 IP:218.19.xxx.xxx 未訂閱
wbs173 您好: 您的程式碼排版沒有縮排,看起來很吃力,因此尚未仔細查看您的程式碼,我僅查看了 ScanLine 這個動作的前後敘述,發現您在程式內設定的幾個值都是固定為 320 或 240,那麼您是否已經確定了您處理的 Image2 的圖像尺寸一定是固定的 240x320,而不會有其它更小的尺寸呢?另外在程式中有兩處作到除法運算,而往前追朔查看被除的 Hmax 與 Vmax 時,可以發現若是圖像上沒有黑點的話這兩個變數會是 0,這將可能導致錯誤的發生。 發表人 - RedSnow 於 2005/04/06 22:32:47
wbs173
一般會員


發表:12
回覆:26
積分:7
註冊:2005-03-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-04-07 00:12:04 IP:219.80.xxx.xxx 未訂閱
抱歉喔 我第一次貼程式碼上來 所以不會貼 再貼一次這樣不知道對不對 taishyang 大大的方法我爬文時試過了 但是還是一樣 我的圖示從CCD擷取的 大小應該固定吧 所以還麻煩會的高手幫忙看看 感恩~ 
void __fastcall TForm1::Timer3Timer(TObject *Sender)
{ 
// 統計水平與垂直方向的投影量
long ProjectV[320] = {0};
long ProjectH[240] = {0};
long Vmax = 0, Hmax = 0;
Byte *ptr;
StringGrid1->Cells[0][1]="垂直";
StringGrid1->Cells[0][2]="水平";
Image3->Canvas->Brush->Color = clWhite;
Image3->Canvas->FillRect(TRect(0,0,Image3->Width,Image3->Height));
Image4->Canvas->Brush->Color = clWhite;
Image4->Canvas->FillRect(TRect(0,0,Image4->Width,Image4->Height));
for(int row = 0; row < 240; row  )
{
ptr = (Byte *)Image2->Picture->Bitmap->ScanLine[row];
for(int col = 0; col < 320; col  )
{
if(col == 0)
StringGrid1->Cells[0][col]="行(列)數";//設定StringGrid中最左上角那一小格的資訊
else StringGrid1->Cells[col][0]=IntToStr(col);//col header的值
if(ptr[col*3] == 0) // 黑點
{
ProjectV[col]  ; // 垂直方向投影的數量 1
ProjectH[row]  ; // 水平方向投影的數量 1
if(ProjectV[col] > Vmax)
Vmax = ProjectV[col]; // 統計垂直投影最大值
if(ProjectH[row] > Hmax)
Hmax = ProjectH[row]; // 統計水平投影最大值
}}}
// 畫出水平方向投影
Image3->Canvas->Pen->Color = clBlack;
for(int row = 1; row <= 240; row  )
{
StringGrid1->Cells[row][2]=IntToStr(ProjectH[row]);//輸出水平方向的加總值
Image3->Canvas->MoveTo(Image3->Width, row);
Image3->Canvas->LineTo(Image3->Width * (1.0 - (double)ProjectH[row] / (double)Hmax), row);
}    // 畫出垂直方向投影
Image4->Canvas->Pen->Color = clBlack;
for(int col = 1; col <= 320; col  )
{
StringGrid1->Cells[col][1]=IntToStr(ProjectV[col]);//輸出垂直方向的加總值
Image4->Canvas->MoveTo(col, Image4->Height);
Image4->Canvas->LineTo(col, Image4->Height * (1.0 - (double)ProjectV[col] / (double)Vmax));
}
 
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-04-07 09:22:12 IP:210.68.xxx.xxx 未訂閱
您好: 我用您的程式碼測試並不會有您說的現象耶,BCB6.0 WinNT 會不會是其他地方的問題?
 
   long ProjectV[320] = {0};
   long ProjectH[240] = {0};
   long Vmax = 0, Hmax = 0;
   Byte *ptr;
   StringGrid1->Cells[0][1]="垂直";
   StringGrid1->Cells[0][2]="水平";
   Image3->Canvas->Brush->Color = clWhite;
   Image3->Canvas->FillRect(TRect(0,0,Image3->Width,Image3->Height));
   Image4->Canvas->Brush->Color = clWhite;
   Image4->Canvas->FillRect(TRect(0,0,Image4->Width,Image4->Height));
   for(int row = 0; row < 240; row  )
   {
      ptr = (Byte *)Image2->Picture->Bitmap->ScanLine[row];
      for(int col = 0; col < 320; col  )
      {
         if(col == 0)
            StringGrid1->Cells[0][col]="行(列)數";//設定StringGrid中最左上角那一小格的資訊
         else
            StringGrid1->Cells[col][0]=IntToStr(col);//col header的值
         if(ptr[col*3] == 0) // 黑點
         {
            ProjectV[col]  ; // 垂直方向投影的數量 1
            ProjectH[row]  ; // 水平方向投影的數量 1
            if(ProjectV[col] > Vmax)
               Vmax = ProjectV[col]; // 統計垂直投影最大值
            if(ProjectH[row] > Hmax)
               Hmax = ProjectH[row]; // 統計水平投影最大值
         }
      }
   }
// 畫出水平方向投影
   Image3->Canvas->Pen->Color = clBlack;
   for(int row = 1; row <= 240; row  )
   {
      StringGrid1->Cells[row][2]=IntToStr(ProjectH[row]);//輸出水平方向的加總值
      Image3->Canvas->MoveTo(Image3->Width, row);
      Image3->Canvas->LineTo(Image3->Width * (1.0 - (double)ProjectH[row] / (double)Hmax), row);
   }    // 畫出垂直方向投影
   Image4->Canvas->Pen->Color = clBlack;
   for(int col = 1; col <= 320; col  )
   {
      StringGrid1->Cells[col][1]=IntToStr(ProjectV[col]);//輸出垂直方向的加總值
      Image4->Canvas->MoveTo(col, Image4->Height);
      Image4->Canvas->LineTo(col, Image4->Height * (1.0 - (double)ProjectV[col] / (double)Vmax));
   }   
順心
wbs173
一般會員


發表:12
回覆:26
積分:7
註冊:2005-03-15

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-04-07 21:17:48 IP:219.80.xxx.xxx 未訂閱
非常感謝taishyang大大 費心看我的程式碼還幫忙RUN 我不知道是哪裡有錯 我貼上我全部的程式好了 希望各位高手不厭其煩幫我看看 感激不盡~ 
//---------------------------------------------------------------------------    #include 
#pragma hdrstop    #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "EzCapCamera"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Timer3Timer(TObject *Sender)
{
 // 統計水平與垂直方向的投影量
  long ProjectV[320] = {0};
  long ProjectH[240] = {0};
  long Vmax = 0, Hmax = 0;
  Byte *ptr;
  StringGrid1->Cells[0][1]="垂直";
  StringGrid1->Cells[0][2]="水平";
  Image3->Canvas->Brush->Color = clWhite;
  Image3->Canvas->FillRect(TRect(0,0,Image3->Width,Image3->Height));
  Image4->Canvas->Brush->Color = clWhite;
  Image4->Canvas->FillRect(TRect(0,0,Image4->Width,Image4->Height));
  for(int row = 0; row < 240; row  )
  {
    ptr = (Byte *)Image2->Picture->Bitmap->ScanLine[row];
    for(int col = 0; col < 320; col  )
    {
      if(col == 0)
      StringGrid1->Cells[0][col]="行(列)數";//設定StringGrid中最左上角那一小格的資訊
      else    StringGrid1->Cells[col][0]=IntToStr(col);//col header的值
      if(ptr[col*3] == 0) // 黑點
      {
        ProjectV[col]  ; // 垂直方向投影的數量 1
        ProjectH[row]  ; // 水平方向投影的數量 1
        if(ProjectV[col] > Vmax)
        Vmax = ProjectV[col]; // 統計垂直投影最大值
        if(ProjectH[row] > Hmax)
        Hmax = ProjectH[row]; // 統計水平投影最大值
      }
    }
  }
  //判斷按下那個鍵
  //按下1
   if(ProjectV[69]>190)
   Edit2->Text=1;
  //按下8
   if(ProjectV[129]>130 && ProjectH[176]>40 && ProjectH[176]<70)
   Edit2->Text=8;
  //按下5
   if(ProjectV[130]>160 && ProjectV[130]<185)
   Edit2->Text=5;
  //按下9
   if(ProjectV[202]>160 && ProjectV[202]<175 && ProjectH[168]>40)
   Edit2->Text=9;
  //按下0
   if(ProjectV[140]>105 && ProjectV[140]<125 && ProjectH[228]>40 && ProjectH[228]<60)
   Edit2->Text=0;
  //按下2
   if(ProjectV[138]>200)
   Edit2->Text=2;
  //按下3
   if(ProjectV[190]>200)
   Edit2->Text=3;
  //按下4
   if(ProjectV[77]>175 && ProjectV[77]<195)
   Edit2->Text=4;
  //按下6
   if(ProjectV[200]>180 && ProjectV[200]<195)
   Edit2->Text=6;
  //按下7
   if(ProjectV[70]>100 && ProjectV[70]<140)
   Edit2->Text=7;
  //按下 
   if(ProjectV[250]>200)
   Edit2->Text=" ";
  //按下-
   if(ProjectV[255]>150 && ProjectV[255]<175)
   Edit2->Text="-";
  //按下*
   if((ProjectV[255]>100 && ProjectV[255]<130) && (ProjectH[170]>30 && ProjectH[170]<50))
   Edit2->Text="*";
  //按下/
   if(ProjectV[255]>60 && ProjectV[255]<80)
   Edit2->Text="/";
  //按下清除
   if((ProjectV[78]>90 && ProjectV[78]<105) && (ProjectH[230]>50 && ProjectH[230]<65))
   Edit2->Text=" ";      // 畫出水平方向投影
  Image3->Canvas->Pen->Color = clBlack;
  for(int row = 1; row <= 240; row  )
  {
    StringGrid1->Cells[row][2]=IntToStr(ProjectH[row]);//輸出水平方向的加總值
    Image3->Canvas->MoveTo(Image3->Width, row);
    Image3->Canvas->LineTo(Image3->Width * (1.0 - (double)ProjectH[row] / (double)Hmax), row);
  }      // 畫出垂直方向投影
  Image4->Canvas->Pen->Color = clBlack;
  for(int col = 1; col <= 320; col  )
  {
    StringGrid1->Cells[col][1]=IntToStr(ProjectV[col]);//輸出垂直方向的加總值
    Image4->Canvas->MoveTo(col, Image4->Height);
    Image4->Canvas->LineTo(col, Image4->Height * (1.0 - (double)ProjectV[col] / (double)Vmax));
  }           
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button1Click(TObject *Sender)
{
Button1->Enabled=False;
 EzCapCamera1->CameraDisplay();   //開啟攝影機功能
 Image2->Visible=True;
 Timer1->Enabled=True;
 Timer2->Enabled=True;
 Button4->Enabled=True;        
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Button1->Enabled=True;
 Timer1->Enabled=False;
 Timer2->Enabled=False; 
 Image2->Visible=False;
 Button4->Enabled=False;
 EzCapCamera1->CameraClose();  //關閉攝影機功能        
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
EzCapCamera1->CapBmpPic("1.bmp");       //將影像存成圖檔        
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
EzCapCamera1->CapBmpPic("2.bmp"); //儲存圖檔    //Image1->Picture->LoadFromFile("2.bmp"); //載入圖檔        
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
EzCapCamera1->VideoSourceDlg();  //開啟攝影機的內部設定        
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
Close();    //關閉程式        
}
//---------------------------------------------------------------------------
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 r,g,b;
 int gray;
 int i,j;
 int threshold;
 threshold=ScrollBar1->Position;
 Edit1->Text=ScrollBar1->Position;
 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];
   gray=0.299*r  0.587*g 0.114*b;
   if(gray>threshold)
    gray=255;
   else
    gray=0;
   ptr[i*3]=(Byte)gray;
   ptr[i*3 1]=(Byte)gray;
   ptr[i*3 2]=(Byte)gray;
  }
 }    //二值化結束
Image2->Picture->Assign(Bmp);//輸出二值化結果        
}
//--------------------------------------------------------------------------- 
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-04-07 23:38:04 IP:218.168.xxx.xxx 未訂閱
您好: 您這次po的程式碼太長我無能為力 可能要請您自行trace了,並將有問題的程式碼範圍逐漸縮小 就可以知道問題大概出在哪邊,再把問題po上來請大家幫您看看 您可以先確認一下scanline的範圍是否正確 您所掃描的圖片是否真是320x240    順心 發表人 -
wbs173
一般會員


發表:12
回覆:26
積分:7
註冊:2005-03-15

發送簡訊給我
#8 引用回覆 回覆 發表時間:2005-04-07 23:54:08 IP:219.80.xxx.xxx 未訂閱
喔喔 那我自己在試試 我只知道我沒加入timer3時run都OK 但是加了以後就不能了 還是謝謝taishyang 幫我看 如果有哪位高手有空的話可以幫忙看看 在下感激不盡~
系統時間:2024-05-12 23:16:00
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!