線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2865
推到 Plurk!
推到 Facebook!

兩張圖重疊定位問題,請教各位前輩

答題得分者是:小傑克
juliuschen00
一般會員


發表:4
回覆:6
積分:2
註冊:2007-08-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-03-17 10:25:25 IP:59.125.xxx.xxx 訂閱
請教各位前輩:
我有一個背景圖和許多的前景圖.
檔案格式都是Jpeg 檔,用同樣的掃瞄器掃瞄.
前景及背景圖上都有一個小正方形黑色的定位點,
我想把前景與貝景的兩張圖重疊顯示.
現在重疊顯示我有想到解法,
但如此作顯示時會有點位移,
我想用圖上的定位點來調整,
可是還沒有任何想法,
不知各位前輩有何建議,
或可搜尋的關鍵字.
謝謝!!
小傑克
資深會員


發表:5
回覆:209
積分:357
註冊:2009-02-16

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-03-17 12:56:55 IP:59.112.xxx.xxx 訂閱
能不能說一下你是如何做重疊顯示,產生什麼樣的點位移,需要怎樣的調整?

===================引 用 juliuschen00 文 章===================
請教各位前輩:
我有一個背景圖和許多的前景圖.
檔案格式都是Jpeg 檔,用同樣的掃瞄器掃瞄.
前景及背景圖上都有一個小正方形黑色的定位點,
我想把前景與貝景的兩張圖重疊顯示.
現在重疊顯示我有想到解法,
但如此作顯示時會有點位移,
我想用圖上的定位點來調整,
可是還沒有任何想法,
不知各位前輩有何建議,
或可搜尋的關鍵字.
謝謝!!
------
額有朝天骨,眼中有靈光
juliuschen00
一般會員


發表:4
回覆:6
積分:2
註冊:2007-08-17

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-03-19 17:06:04 IP:59.125.xxx.xxx 訂閱
謝謝前輩.
我是用for 迴圈將兩個jpg 的pixel 讀出,
然後加起來到第3個jpg 檔,
如此第3個jpg 檔就可show 出1,2張jpg 的組合了.

現在問題是如此作如果紙張的大小差1mm,
前景與背景掃出的圖檔組起來感覺就沒有重疊再一起.
因為每個紙張上面都有一個黑色的正方型定位點.
如果前景與背景掃描出來的jpg 檔定位點能正好重疊,
那位置就準了.

謝謝!!




===================引 用 小傑克 文 章===================
能不能說一下你是如何做重疊顯示,產生什麼樣的點位移,需要怎樣的調整?

===================引 用 juliuschen00 文 章===================
請教各位前輩:
我有一個背景圖和許多的前景圖.
檔案格式都是Jpeg 檔,用同樣的掃瞄器掃瞄.
前景及背景圖上都有一個小正方形黑色的定位點,
我想把前景與貝景的兩張圖重疊顯示.
現在重疊顯示我有想到解法,
但如此作顯示時會有點位移,
我想用圖上的定位點來調整,
可是還沒有任何想法,
不知各位前輩有何建議,
或可搜尋的關鍵字.
謝謝!!
小傑克
資深會員


發表:5
回覆:209
積分:357
註冊:2009-02-16

發送簡訊給我
#4 引用回覆 回覆 發表時間:2009-03-19 18:41:46 IP:59.112.xxx.xxx 訂閱
疑? 你不是把答案說出來了嗎?
1. 用for loop 先找到兩張定位點座標
2. 把 每個pixel - 座標差 再去相加...
你的問題是....演算法很慢嗎?

我想,既然是當作定位點,應該是在紙張邊界附近,應該不用花很多時間就可以搜尋到
找的方法不外乎抓一個方框來判斷
Canvas.Pixels[X,Y] <-- 跑for loop取位置顏色 找到P1的定位點(x1,y1) P2的定位點(x2,y2)
P3.Canvas.Pixels[X,Y] := P1.Canvas.Pixels[X,Y] P2.Canvas.Pixels[X -(x2-x1),Y- (y2-y1)] <--顏色位移後相加


===================引 用 juliuschen00 文 章===================
謝謝前輩.
我是用for 迴圈將兩個jpg 的pixel 讀出,
然後加起來到第3個jpg 檔,
如此第3個jpg 檔就可show 出1,2張jpg 的組合了.

現在問題是如此作如果紙張的大小差1mm,
前景與背景掃出的圖檔組起來感覺就沒有重疊再一起.
因為每個紙張上面都有一個黑色的正方型定位點.
如果前景與背景掃描出來的jpg 檔定位點能正好重疊,
那位置就準了.

謝謝!!

------
額有朝天骨,眼中有靈光
juliuschen00
一般會員


發表:4
回覆:6
積分:2
註冊:2007-08-17

發送簡訊給我
#5 引用回覆 回覆 發表時間:2009-03-23 15:32:48 IP:59.125.xxx.xxx 訂閱

如前輩所講的.目前我的問題在於取 P1的定位點(x1,y1) P2的定位點(x2,y2) .

定位點可能是 10 X 10 pixel 的黑色正方形.它藏在jpg 的某個地方.
要完全符合才算.
如果我用 for loop 去作,而且兩張圖都要作,我在想有沒有較快的作法.


謝謝!!

===================引 用 小傑克 文 章===================
疑? 你不是把答案說出來了嗎?
1. 用for loop 先找到兩張定位點座標
2. 把 每個pixel - 座標差 再去相加...
你的問題是....演算法很慢嗎?

我想,既然是當作定位點,應該是在紙張邊界附近,應該不用花很多時間就可以搜尋到
找的方法不外乎抓一個方框來判斷
Canvas.Pixels[X,Y] <-- 跑for loop取位置顏色 找到P1的定位點(x1,y1) P2的定位點(x2,y2)
P3.Canvas.Pixels[X,Y] := P1.Canvas.Pixels[X,Y] P2.Canvas.Pixels[X -(x2-x1),Y- (y2-y1)] <--顏色位移後相加


===================引 用 juliuschen00 文 章===================
謝謝前輩.
我是用for 迴圈將兩個jpg 的pixel 讀出,
然後加起來到第3個jpg 檔,
如此第3個jpg 檔就可show 出1,2張jpg 的組合了.

現在問題是如此作如果紙張的大小差1mm,
前景與背景掃出的圖檔組起來感覺就沒有重疊再一起.
因為每個紙張上面都有一個黑色的正方型定位點.
如果前景與背景掃描出來的jpg 檔定位點能正好重疊,
那位置就準了.

謝謝!!
?
小傑克
資深會員


發表:5
回覆:209
積分:357
註冊:2009-02-16

發送簡訊給我
#6 引用回覆 回覆 發表時間:2009-03-23 20:55:16 IP:59.112.xxx.xxx 訂閱
我沒在玩圖形,也許另有高手可以幫忙
但我可以提供一個我的想法, 一個定位點是10x10 , 那我用3x3 網點先去找出吻合的位置,再去檢查是不是定位點
3x3 是這樣檢查 (x,y)=(x,y 3)=(x,y 6)=(x 3,y)=(x 3,y 3)=(x 3,y 6)=(x 6,y)=(x 6,y 3)=(x 6,y 6) = clBlack 因為10x10 無論如何一定可以包含這九個點
如果吻合的話, 定位點必然在 ( x 3,y 3) 前後左右 6 的範圍之內,我試寫一個跑起來還算快,找 10個定位點也只要0.25秒

想要再更快點可以把ii,jj 那段寫成function , Image1.Canvas.Pixels[i ii,j jj] <> clBlack 裡面用 break 這樣檢查可以更快

我測試程式貼在這
http://delphi.ktop.com.tw/board.php?cid=32&fid=911&tid=97663

但有一點我有點懷疑,圖形是掃描進來的,能夠確保定位點是10x10嗎? 會不會有扭曲變形阿, 而且實際畫了10x10後才發現這點還蠻大的

[code delphi]
procedure TForm1.Button2Click(Sender: TObject);
var ix,iy:integer;
P:TPoint;
t1,t2:TDateTime;
function MakeSurePos(x,y:integer):TPoint;
var i,j:integer;
ii,jj:integer;
isBlack:boolean;
begin
Result.X := -1;
Result.Y := -1;
for i := x-6 to x-3 do
begin
for j := y-6 to y-3 do
begin
isBlack := true;
for ii := 0 to 9 do
for jj := 0 to 9 do
if Image1.Canvas.Pixels[i ii,j jj] <> clBlack then
isBlack := false;
if isBlack then
begin
Result.X := i;
Result.Y := j;
end;
end; // j
end;// i
end;
begin
t1 := now;
ix := 1;
repeat
iy := 1;
repeat
with Image1.Canvas do
begin //用這個 if 縮小檢查範圍
if (Pixels[ix,iy]=clBlack) and (Pixels[ix,iy 3]=clBlack) and (Pixels[ix,iy 6]=clBlack)
and (Pixels[ix 3,iy]=clBlack) and (Pixels[ix 3,iy 3]=clBlack) and (Pixels[ix 3,iy 6]=clBlack)
and (Pixels[ix 6,iy]=clBlack) and (Pixels[ix 6,iy 3]=clBlack) and (Pixels[ix 6,iy 6]=clBlack) then
begin
p := MakeSurePos(ix 3,iy 3);
//(Memo2.Lines.IndexOf(IntToStr(P.X) ',' IntToStr(P.Y))= -1) 這是因為如果剛好 ix,iy 在定位點的邊界上, 0,3,6,9
//會有 0,3,6 and 3,6,9 都可以吻合的狀況
if (p.X <> -1)and (Memo2.Lines.IndexOf(IntToStr(P.X) ',' IntToStr(P.Y))= -1) then
Memo2.Lines.Add(IntToStr(P.X) ',' IntToStr(P.Y));
end;
end;
iy := iy 3;
until iy > Image1.Height - 5;
ix := ix 3;
until ix > Image1.Width - 5 ;
t2 := now;
Caption := FormatDateTime('ss.zzz',t2-t1);
end;

[/code]
------
額有朝天骨,眼中有靈光
編輯記錄
小傑克 重新編輯於 2009-03-23 21:02:59, 註解 無‧
小傑克
資深會員


發表:5
回覆:209
積分:357
註冊:2009-02-16

發送簡訊給我
#7 引用回覆 回覆 發表時間:2009-03-23 21:55:24 IP:59.112.xxx.xxx 訂閱
這樣寫 1041 x 610  的圖掃一遍只要0.18秒, 給你參考
[code delphi]
procedure TForm1.Button2Click(Sender: TObject);
var ix,iy:integer;
P:TPoint;
t1,t2:TDateTime;
function MakeSurePos(x,y:integer):TPoint;
var i,j:integer;
function isBlack:Boolean;
var ii,jj:integer;
begin
Result := true;
for ii := 0 to 9 do
for jj := 0 to 9 do
if Image1.Canvas.Pixels[i ii,j jj] <> clBlack then
begin
Result := false;
exit;
end;
end;
begin
Result.X := -1;
Result.Y := -1;
for i := x-6 to x-3 do
begin
for j := y-6 to y-3 do
begin
if isBlack then
begin
Result.X := i;
Result.Y := j;
end;
end; // j
end;// i
end;
begin
t1 := now;
ix := 1;
repeat
iy := 1;
repeat
with Image1.Canvas do
begin //用這個 if 縮小檢查範圍
if (Pixels[ix,iy]=clBlack) and (Pixels[ix,iy 3]=clBlack) and (Pixels[ix,iy 6]=clBlack)
and (Pixels[ix 3,iy]=clBlack) and (Pixels[ix 3,iy 3]=clBlack) and (Pixels[ix 3,iy 6]=clBlack)
and (Pixels[ix 6,iy]=clBlack) and (Pixels[ix 6,iy 3]=clBlack) and (Pixels[ix 6,iy 6]=clBlack) then
begin
p := MakeSurePos(ix 3,iy 3);
//(Memo2.Lines.IndexOf(IntToStr(P.X) ',' IntToStr(P.Y))= -1) 這是因為如果剛好 ix,iy 在定位點的邊界上, 0,3,6,9
//會有 0,3,6 and 3,6,9 都可以吻合的狀況
if (p.X <> -1)and (Memo2.Lines.IndexOf(IntToStr(P.X) ',' IntToStr(P.Y))= -1) then
Memo2.Lines.Add(IntToStr(P.X) ',' IntToStr(P.Y));
end;
end;
iy := iy 3;
until iy > Image1.Height - 5;
ix := ix 3;
until ix > Image1.Width - 5 ;
t2 := now;
Caption := FormatDateTime('ss.zzz',t2-t1);
end;
[/code]


對照全圖掃描,這個要0.96秒
[code delphi]
procedure TForm1.Button3Click(Sender: TObject);
var i,j:integer;
t1,t2:TDateTime;
function isBlack():boolean;
var ii,jj:integer;
begin
Result := true;
for ii := 0 to 9 do
begin
for jj := 0 to 9 do
begin
if Image1.Canvas.Pixels[i ii,j jj] <> clblack then
begin
Result := false;
exit;
end;
end;
end;
end;
begin
t1 := now;
for i := 0 to Image1.Width-9 do
begin
for j := 0 to Image1.Height-9 do
begin
if isBlack then
Memo2.Lines.Add(IntToStr(i) ',' IntToStr(j));
end;
end;
t2 := now;
Caption := FormatDateTime('ss.zzz',t2-t1);
end;
[/code]
------
額有朝天骨,眼中有靈光
juliuschen00
一般會員


發表:4
回覆:6
積分:2
註冊:2007-08-17

發送簡訊給我
#8 引用回覆 回覆 發表時間:2009-03-24 14:37:49 IP:59.125.xxx.xxx 訂閱
感謝!! 
本來我只是需要想法,想不到前輩連範例都寫好了,,,
非常感謝!!


===================引 用 小傑克 文 章===================
這樣寫 1041 x 610 的圖掃一遍只要0.18秒, 給你參考
[code delphi]
procedure TForm1.Button2Click(Sender: TObject);
var ix,iy:integer;
P:TPoint;
t1,t2:TDateTime;
function MakeSurePos(x,y:integer):TPoint;
var i,j:integer;
function isBlack:Boolean;
var ii,jj:integer;
begin
Result := true;
for ii := 0 to 9 do
for jj := 0 to 9 do
if Image1.Canvas.Pixels[i ii,j jj] <> clBlack then
begin
Result := false;
exit;
end;
end;
begin
Result.X := -1;
Result.Y := -1;
for i := x-6 to x-3 do
begin
for j := y-6 to y-3 do
begin
if isBlack then
begin
Result.X := i;
Result.Y := j;
end;
end; // j
end;// i
end;
begin
t1 := now;
ix := 1;
repeat
iy := 1;
repeat
with Image1.Canvas do
begin //用這個 if 縮小檢查範圍
if (Pixels[ix,iy]=clBlack) and (Pixels[ix,iy 3]=clBlack) and (Pixels[ix,iy 6]=clBlack)
and (Pixels[ix 3,iy]=clBlack) and (Pixels[ix 3,iy 3]=clBlack) and (Pixels[ix 3,iy 6]=clBlack)
and (Pixels[ix 6,iy]=clBlack) and (Pixels[ix 6,iy 3]=clBlack) and (Pixels[ix 6,iy 6]=clBlack) then
begin
p := MakeSurePos(ix 3,iy 3);
//(Memo2.Lines.IndexOf(IntToStr(P.X) ',' IntToStr(P.Y))= -1) 這是因為如果剛好 ix,iy 在定位點的邊界上, 0,3,6,9
//會有 0,3,6 and 3,6,9 都可以吻合的狀況
if (p.X <> -1)and (Memo2.Lines.IndexOf(IntToStr(P.X) ',' IntToStr(P.Y))= -1) then
Memo2.Lines.Add(IntToStr(P.X) ',' IntToStr(P.Y));
end;
end;
iy := iy 3;
until iy > Image1.Height - 5;
ix := ix 3;
until ix > Image1.Width - 5 ;
t2 := now;
Caption := FormatDateTime('ss.zzz',t2-t1);
end;
[/code]


對照全圖掃描,這個要0.96秒
[code delphi]
procedure TForm1.Button3Click(Sender: TObject);
var i,j:integer;
t1,t2:TDateTime;
function isBlack():boolean;
var ii,jj:integer;
begin
Result := true;
for ii := 0 to 9 do
begin
for jj := 0 to 9 do
begin
if Image1.Canvas.Pixels[i ii,j jj] <> clblack then
begin
Result := false;
exit;
end;
end;
end;
end;
begin
t1 := now;
for i := 0 to Image1.Width-9 do
begin
for j := 0 to Image1.Height-9 do
begin
if isBlack then
Memo2.Lines.Add(IntToStr(i) ',' IntToStr(j));
end;
end;
t2 := now;
Caption := FormatDateTime('ss.zzz',t2-t1);
end;
[/code]
系統時間:2024-04-27 10:32:57
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!