จัดการรูปภาพในความหมายของผมคือ สมมุติ ถ่ายรูปกระดาษ A4 แนวเอียง ปรกติต้องตั้งฉาก 90 องศา กับกระดาษจึงจะเป็นรูปที่ถูกต้อง แต่บางครั้งเกิดถ่ายเอียงไป 120 องศา แบบนี้จะสามารถเขียน Autoit ให้ดึงภาพเอียงนั้นเป็นภาพตรงได้รึปล่าวครับ
2 posters
Autoit สามารถเขียนโปรแกรมจัดการรูปภาพได้รึปล่าวครับ
sirchet- PSsix Member High Class
จำนวนข้อความ : 96
ความนิยม : 1
เข้าร่วมเมื่อ : 21/07/2010
อายุ : 35
POS- PSsix
-
จำนวนข้อความ : 1152
ความนิยม : 326
เข้าร่วมเมื่อ : 19/07/2010
ยากครับ แทบเป็นไปไม่ได้ ขั้นแรกต้องเขียนสคริปต์หาองศาของรูปกระดาษที่หมุน (ผมไม่รู้ว่าจะเขียนอย่างไร) หลักการนะทำได้ เช่น ตัวอย่าง
[You must be registered and logged in to see this image.]
1. หาจุดต่ำสุด สันนิษฐานว่าเป็นมุมของขอบรูปด้านล่างที่เอียง
2. หาจุดไกลสุดที่อยู่ทางขวา สันนิษฐานว่าเป็นมุมของขอบรูปด้านบนที่เอียง
นำเอาพิกัด x y ทั้งสองตำแหน่งมาลบกัน แล้วใช้สูตรหาองศา ก็จะได้สคริปต์ด้านล่างนี้
แต่ในสภาพความเป็นจริง รูปหากเป็นรูปที่สแกนมาจะมีเกรน(พวกจุดลาย)และข้อบกพร่องที่ทำให้การหาจุดอ้างอิงเพี้ยนไป ตรงนี้จะเป็นส่วนที่ยาก เพราะถ้าเพี้ยนไปนิดเดียวองศาที่ได้ก็จะผิด การสั่งหมุนรูปก็จะกลายเป็นหมุนแล้วไม่ตรงไปอีก
ส่วนการหมุนภาพใช้สคริปต์ดังตัวอย่างด้านล่างนี้
[You must be registered and logged in to see this image.]
1. หาจุดต่ำสุด สันนิษฐานว่าเป็นมุมของขอบรูปด้านล่างที่เอียง
2. หาจุดไกลสุดที่อยู่ทางขวา สันนิษฐานว่าเป็นมุมของขอบรูปด้านบนที่เอียง
นำเอาพิกัด x y ทั้งสองตำแหน่งมาลบกัน แล้วใช้สูตรหาองศา ก็จะได้สคริปต์ด้านล่างนี้
แต่ในสภาพความเป็นจริง รูปหากเป็นรูปที่สแกนมาจะมีเกรน(พวกจุดลาย)และข้อบกพร่องที่ทำให้การหาจุดอ้างอิงเพี้ยนไป ตรงนี้จะเป็นส่วนที่ยาก เพราะถ้าเพี้ยนไปนิดเดียวองศาที่ได้ก็จะผิด การสั่งหมุนรูปก็จะกลายเป็นหมุนแล้วไม่ตรงไปอีก
- Code:
$x = 340-237
$y = 374-539
$degree = Abs(Round(ATan($y / $x ) * 180 / 3.1415926, 1))
MsgBox(0,"" ,"ภาพหมุน " & $degree )
ส่วนการหมุนภาพใช้สคริปต์ดังตัวอย่างด้านล่างนี้
- Code:
#include <GDIPlus.au3>
_GDIPlus_Startup()
Local $hImg = _GDIPlus_ImageLoadFromFile("aa.jpg") ;;โหลดภาพ
_GDIPlus_ImageRotateFlip($hImg, 1) ;หมุนภาพ
_GDIPlus_ImageSaveToFile($hImg, "Test.png") ;;เซฟภาพ
_GDIPlus_ImageDispose($hImg)
_GDIPlus_Shutdown()
; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_ImageRotateFlip
; Description ...: Rotates and flips an image
; Syntax.........: _GDIPlus_ImageRotateFlip($hImage, $iRotateFlipType)
; Parameters ....: $hImage - Pointer to an Image object
; $iRotateFlipType - Type of rotation and flip:
; |0 - No rotation and no flipping (A 180-degree rotation, a horizontal flip and then a vertical flip)
; |1 - A 90-degree rotation without flipping (A 270-degree rotation, a horizontal flip and then a vertical flip)
; |2 - A 180-degree rotation without flipping (No rotation, a horizontal flip folow by a vertical flip)
; |3 - A 270-degree rotation without flipping (A 90-degree rotation, a horizontal flip and then a vertical flip)
; |4 - No rotation and a horizontal flip (A 180-degree rotation followed by a vertical flip)
; |5 - A 90-degree rotation followed by a horizontal flip (A 270-degree rotation followed by a vertical flip)
; |6 - A 180-degree rotation followed by a horizontal flip (No rotation and a vertical flip)
; |7 - A 270-degree rotation followed by a horizontal flip (A 90-degree rotation followed by a vertical flip)
; Return values .: Success - True
; Failure - False
; Remarks .......: None
; Related .......: None
; Link ..........; @@MsdnLink@@ GdipImageRotateFlip
; Example .......; No
; ===============================================================================================================================
Func _GDIPlus_ImageRotateFlip($hImage, $iRotateFlipType)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipImageRotateFlip", "hwnd", $hImage, "int", $iRotateFlipType)
Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc ;==>_GDIPlus_ImageRotateFlip
sirchet- PSsix Member High Class
จำนวนข้อความ : 96
ความนิยม : 1
เข้าร่วมเมื่อ : 21/07/2010
อายุ : 35
ขอบคุณครับ Admin POS
จริงๆ แล้วผมอยากทำเครื่องสแกนหนังสือโดยใช้กล้องถ่ายรูปหลักการเป็นแบบในภาพครับ
จะเป็นไปได้ไหมที่ใช้ Autoit ทำโปรแกรมตัดภาพ และโปรแกรมดึงภาพ ในรูปครับ[img][You must be registered and logged in to see this image.] [/img]
จริงๆ แล้วผมอยากทำเครื่องสแกนหนังสือโดยใช้กล้องถ่ายรูปหลักการเป็นแบบในภาพครับ
จะเป็นไปได้ไหมที่ใช้ Autoit ทำโปรแกรมตัดภาพ และโปรแกรมดึงภาพ ในรูปครับ[img][You must be registered and logged in to see this image.] [/img]
POS- PSsix
-
จำนวนข้อความ : 1152
ความนิยม : 326
เข้าร่วมเมื่อ : 19/07/2010
ถ้าต้องการแบบนั้น คุณคงต้องเขียนสคริปต์
-เขียนสคริปต์หาจุดกึ่งกลางภาพเพื่อตัด
- ได้จุดกึ่งกลางใช้สคริปต์ตัดภาพออก (ตัวอย่างสคริปต์ด้านล่าง)
- จากนั้นก็เขียนสคริปต์หามุมทั้งสี่ของภาพที่ตัด ตรงนี้ผมก็ยังนึกไม่ออกมาจะเขียนอย่างไรไม่ให้ผิดพลาด
- เมื่อได้มุมแล้วก็ปรับบิดเอียงภาพให้มุมเท่ากับ (ตัวอย่างสคริปต์ด้านล่าง)
สคริปต์ ตัดภาพ
สคริปต์เอียงภาพ รายละเอียดอื่นๆ [You must be registered and logged in to see this link.]
-เขียนสคริปต์หาจุดกึ่งกลางภาพเพื่อตัด
- ได้จุดกึ่งกลางใช้สคริปต์ตัดภาพออก (ตัวอย่างสคริปต์ด้านล่าง)
- จากนั้นก็เขียนสคริปต์หามุมทั้งสี่ของภาพที่ตัด ตรงนี้ผมก็ยังนึกไม่ออกมาจะเขียนอย่างไรไม่ให้ผิดพลาด
- เมื่อได้มุมแล้วก็ปรับบิดเอียงภาพให้มุมเท่ากับ (ตัวอย่างสคริปต์ด้านล่าง)
สคริปต์ ตัดภาพ
- Code:
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
Opt("MustDeclareVars", 1)
; ===============================================================================================================================
; Description ...: Shows how to slice up an image and then put it back together
; Author ........: Paul Campbell (PaulIA)
; Notes .........:
; ===============================================================================================================================
; ===============================================================================================================================
; Global variables
; ===============================================================================================================================
Global $iI, $hBitmap, $hGraphic, $hGUI, $hImage, $aSlice[4]
; ===============================================================================================================================
; Main
; ===============================================================================================================================
; Capture screen region
$hBitmap = _ScreenCapture_Capture("", 0, 0, 400, 400)
; Create GUI
$hGUI = GUICreate("Slicer", 400, 400)
GUISetState()
; Initialize GDI+ library
_GDIPlus_Startup()
; Slice up screen capture into 4 equal parts
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
$aSlice[0] = _GDIPlus_BitmapCloneArea($hImage, 0, 0, 200, 200)
$aSlice[1] = _GDIPlus_BitmapCloneArea($hImage, 200, 0, 200, 200)
$aSlice[2] = _GDIPlus_BitmapCloneArea($hImage, 0, 200, 200, 200)
$aSlice[3] = _GDIPlus_BitmapCloneArea($hImage, 200, 200, 200, 200)
; Show each slice
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
for $iI = 0 to 3
_GDIPlus_GraphicsDrawImage($hGraphic, $aSlice[$iI], 100, 100)
Sleep(2000)
next
; Stitch slices back together again and display
_GDIPlus_GraphicsDrawImage($hGraphic, $aSlice[0], 0, 0)
_GDIPlus_GraphicsDrawImage($hGraphic, $aSlice[1], 200, 0)
_GDIPlus_GraphicsDrawImage($hGraphic, $aSlice[2], 0, 200)
_GDIPlus_GraphicsDrawImage($hGraphic, $aSlice[3], 200, 200)
; Loop until user exits
do
until GUIGetMsg() = $GUI_EVENT_CLOSE
; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic )
_GDIPlus_ImageDispose ($aSlice[0])
_GDIPlus_ImageDispose ($aSlice[1])
_GDIPlus_ImageDispose ($aSlice[2])
_GDIPlus_ImageDispose ($aSlice[3])
_GDIPlus_GraphicsDispose($hImage )
_WinAPI_DeleteObject ($hBitmap )
; Shut down GDI+ library
_GDIPlus_ShutDown()
สคริปต์เอียงภาพ รายละเอียดอื่นๆ [You must be registered and logged in to see this link.]
- Code:
InetGet("http://www.qld.waterwatch.org.au/images/resources/croc.jpg",@DesktopDir&"\croc.jpg")
#include <GDIPlus.au3>
Global $width=500
Global $height=300
$hwnd=GUICreate("test",$width,$height)
GUISetState()
_GDIPlus_Startup()
$graphics=_GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsClear($graphics,0xFF008800)
$image=_GDIPlus_ImageLoadFromFile(@DesktopDir&"\croc.jpg")
$iwidth=_GDIPlus_ImageGetWidth($image)
$iheight=_GDIPlus_ImageGetHeight($image)
$brush=_GDIPlus_BrushCreateSolid(0xFF000000)
$family=_GDIPlus_FontFamilyCreate("Arial")
$font=_GDIPlus_FontCreate($family,24)
$layout=_GDIPlus_RectFCreate(0,0,$width,$height)
$format=_GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($format,1)
$centerposx=($width/2)-($iwidth/2)
$centerposy=($height/2)-($iheight/2)
_GDIplus_GraphicsDrawStringEx($graphics,"Normal",$font,$layout,$format,$brush)
_GDIPlus_GraphicsDrawImageRect($graphics,$image,$centerposx,$centerposy,$iwidth,$iheight)
Sleep(1500)
_GDIPlus_GraphicsClear($graphics,0xFF008800)
_GDIplus_GraphicsDrawStringEx($graphics,"Skew",$font,$layout,$format,$brush)
_GDIPlus_DrawImagePoints($graphics,$image,$centerposx+0,$centerposy+40,$centerposx+$iwidth,$centerposy-40,$centerposx,$centerposy+$iheight+40,3)
Sleep(1500)
Do
Until GUIGetMsg()=-3
_GDIPlus_ImageDispose($image)
_GDIPlus_BrushDispose($brush)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_FontDispose($font)
_GDIPlus_FontFamilyDispose($family)
_GDIPlus_StringFormatDispose($format)
_GDIPlus_Shutdown()
sirchet- PSsix Member High Class
จำนวนข้อความ : 96
ความนิยม : 1
เข้าร่วมเมื่อ : 21/07/2010
อายุ : 35
ขอบคุณครับ ถ้าผมทำเสร็จจะนำมาดูครับ
|
|