AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Capture From Screen To ASCII Art
Goto page Previous  1, 2
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
1991



Joined: 20 Jan 2006
Posts: 29
Location: Colorado, USA

PostPosted: Sat Mar 04, 2006 7:23 pm    Post subject: Reply with quote

Code:

magnify=1      ;default magnification  NOTE: 2 = 1/2  3=1/3....

^!x::      ;ctrl+alt+x
inputbox, magnify
return

~^!z::      ;ctrl+alt+z

stop=0

#persistent
CoordMode, Mouse, Screen
CoordMode, Tooltip, Screen
MouseGetPos, scan_x_start, scan_y_start
currentXpos=%scan_x_start%
currentYpos=%scan_y_start%
ToolTip, ., scan_x_start, scan_y_start

WinSet, Transparent, 100, ahk_class tooltips_class32

loop
{


MouseGetPos, scan_x, scan_y
scan_x-=%currentXpos%
scan_y-=%currentYpos%
WinMove, ahk_class tooltips_class32, , , , %scan_x%, %scan_y%

GetKeyState, state, z

if state=u
{
tooltip
break
}

}

MouseGetPos, scan_x_end, scan_y_end

TrayTip, , Scanning...., , 1


CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
MouseGetPos, scan_x_end, scan_y_end

scan_current_y=%scan_y_start%
scan_current_x=%scan_x_start%
scan_current_line=
Loop
{
    scan_current_x := scan_current_x + magnify
    if scan_current_x > %scan_x_end%
    {
        scan_current_line =%scan_current_line%`r`n
        scan_current_y := scan_current_y + magnify
        if scan_current_y > %scan_y_end%
            break
        scan_current_x = %scan_x_start%
        continue
    }
    PixelGetColor, found_color, %scan_current_x%, %scan_current_y%
    StringMid, scan_rgb_r, found_color, 3, 2
    StringMid, scan_rgb_g, found_color, 5, 2
    StringMid, scan_rgb_b, found_color, 7, 2
    scan_rgb_r=0x%scan_rgb_r%
    scan_rgb_g=0x%scan_rgb_g%
    scan_rgb_b=0x%scan_rgb_b%
    SetFormat, integer, hex
    scan_rgb_sum:=scan_rgb_r + scan_rgb_g + scan_rgb_b
    if scan_rgb_sum > 0x2d9
    {
      scan_current_line =%scan_current_line%.
    }
    else if scan_rgb_sum > 0x294
    {
      scan_current_line =%scan_current_line%:
    }
    else if scan_rgb_sum > 0x273
    {
      scan_current_line =%scan_current_line%;
    }
    else if scan_rgb_sum > 0x258
    {
      scan_current_line =%scan_current_line%t
    }
    else if scan_rgb_sum > 0x1b9
    {
      scan_current_line =%scan_current_line%j
    }
    else if scan_rgb_sum > 0x1a7
    {
      scan_current_line =%scan_current_line%f
    }
    else if scan_rgb_sum > 0x1b3
    {
      scan_current_line =%scan_current_line%L
    }
    else if scan_rgb_sum > 0x138
    {
      scan_current_line =%scan_current_line%G
    }
    else if scan_rgb_sum > 0x108
    {
      scan_current_line =%scan_current_line%D
    }
    else if scan_rgb_sum > 0xe1
    {
      scan_current_line =%scan_current_line%K
    }
    else if scan_rgb_sum > 0xbd
    {
      scan_current_line =%scan_current_line%W
    }
    else
    {
      scan_current_line =%scan_current_line%#
    }
}
Clipboard=%scan_current_line%
TrayTip, , Scan complete, , 1
sleep, 1000
TrayTip
return


This script 'skips' a specified # of pixels to look at.
It helps in speed and font size.


ALSO: I found 'terminal' font works the best bc it is a constant size and also allows very small fonts Shocked


Im going to work on averaging pixels soon (depending on homework)!
Back to top
View user's profile Send private message
m2



Joined: 13 Jul 2006
Posts: 4

PostPosted: Thu Jul 13, 2006 7:54 pm    Post subject: Export to image-file for later processing Reply with quote

Hi

Modified a bit and, to be able for later imageprocessing using ocr and ultamatly posting the ocr result to a search engine.

This script just makes the ppm image file, kind of screengrap.

Code:

/*

Screen capture script, to make ppm image files.

Format for PPM image file

P3
# example from the man page
4 4
15
 0  0  0    0  0  0    0  0  0   15  0 15
 0  0  0    0 15  7    0  0  0    0  0  0
 0  0  0    0  0  0    0 15  7    0  0  0
15  0 15    0  0  0    0  0  0    0  0  0

*/

~^LButton::

stop=0

#persistent
CoordMode, Mouse, Screen
CoordMode, Tooltip, Screen
MouseGetPos, scan_x_start, scan_y_start
currentXpos=%scan_x_start%
currentYpos=%scan_y_start%
ToolTip, ., scan_x_start, scan_y_start

WinSet, Transparent, 100, ahk_class tooltips_class32

loop
{


MouseGetPos, scan_x, scan_y
scan_x-=%currentXpos%
scan_y-=%currentYpos%
WinMove, ahk_class tooltips_class32, , , , %scan_x%, %scan_y%

GetKeyState, state, LButton

if state=u
{
tooltip
break
}

}

MouseGetPos, scan_x_end, scan_y_end

TrayTip, , Scanning...., , 1


CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
MouseGetPos, scan_x_end, scan_y_end

scan_current_y=%scan_y_start%
scan_current_x=%scan_x_start%
scan_current_line=
scan_current_line_source=
Loop
{
    scan_current_x := scan_current_x + 1
    if scan_current_x > %scan_x_end%
    {
        scan_current_line =%scan_current_line%`n
        scan_current_line_source =%scan_current_line_source%`n
      
        scan_current_y := scan_current_y + 1
        if scan_current_y > %scan_y_end%
            break
        scan_current_x = %scan_x_start%
        continue
    }
    PixelGetColor, found_color, %scan_current_x%, %scan_current_y%
   
   StringMid, scan_rgb_r, found_color, 3, 2
    StringMid, scan_rgb_g, found_color, 5, 2
    StringMid, scan_rgb_b, found_color, 7, 2
   
   scan_current_line_source =%scan_current_line_source% %found_color%

   scan_rgb_r =0x%scan_rgb_r%
   scan_rgb_g =0x%scan_rgb_g%
   scan_rgb_b =0x%scan_rgb_b%

   SetFormat, integer, d
   scan_rgb_r -= 0
   scan_rgb_g -= 0
   scan_rgb_b -= 0

   scan_rgb_r := "   " . scan_rgb_r
   scan_rgb_g := "   " . scan_rgb_g
   scan_rgb_b := "   " . scan_rgb_b

   StringRight, scan_rgb_r, scan_rgb_r, 3
   StringRight, scan_rgb_g, scan_rgb_g, 3
   StringRight, scan_rgb_b, scan_rgb_b, 3
   
   found_color =%scan_rgb_r% %scan_rgb_g% %scan_rgb_b%
   
   ;scan_current_line=%scan_current_line% %found_color%
   ;/*
   if scan_current_x > %scan_x_start%
   {
      scan_current_line=%scan_current_line% %found_color%
   }
   else
   {
      scan_current_line=%scan_current_line%%found_color%
   }
   ;*/
}

; Add Header

format :="P3"
comment :="#File made in Autohotkey"
hight :=scan_y_end - scan_y_start
width :=scan_x_end - scan_x_start
colors :="255"

/*
MsgBox,
(
The hight is %hight%, %scan_y_start% - %scan_y_end% .
The widht is %width%, %scan_x_start% - %scan_x_end%.
)
*/

scan_current_line =
(
%format%
%comment%
%width%
%hight%
%colors%
%scan_current_line%
)

Clipboard=%scan_current_line%
TrayTip, , Scan complete, , 1
sleep, 1000
TrayTip

/*
Only for debug

Gui, Add, Text, x5 y5 w200 h20, The hight is %hight%, %scan_y_start% - %scan_y_end%.
Gui, Add, Text, x5 y25 w200 h20, The width is %width%, %scan_x_start% - %scan_x_end%.
gui, font,s1, Terminal
Gui, Add, Edit, x5 y50 w600 h200 -wrap +HScroll +VScroll, %scan_current_line%
Gui, Add, Edit, x5 y280 w600 h200 -wrap +HScroll +VScroll, %scan_current_line_source%
Gui, Show, h560 w620, Ascii Art
*/

FileSave:
   FileSelectFile, SelectedFile, 16, , Open/name a file, (*.ppm)
   if SelectedFile =
      MsgBox, No file selected.
   else
      SaveCurrentFile:
      IfExist %SelectedFile%
      {
         FileDelete %SelectedFile%
         if ErrorLevel <> 0
         {   
            MsgBox The attempt to overwrite "%SelectedFile%" failed.
            return
         }
      }
      FileAppend, %scan_current_line%, *%SelectedFile%
      Return
Return
Back to top
View user's profile Send private message
FriesWithMustard



Joined: 15 Aug 2006
Posts: 5

PostPosted: Tue Oct 03, 2006 9:58 pm    Post subject: Reply with quote

meod wrote:
is there any way of making the final ascii art smaller...i realize the original size matters, but it comes out too big even with a small image


It kind of needs to be the size that it is -- think of it as a mosaic where the tiles are the size of the individual characters (i.e. the tile with the period ('.') on it is the same size as the tile with the pound sign ('#') -- assuming a Fixed Font is used [which, BTW, is the only kind of font that really works for this]).

Each tile represents a pixel in the image. The reason the 'pixels' have to be so big can be understood by thinking about how shades of gray are simulated using something that is composed of only black and white. The period character is composed of one black dot surrounded by a lot of white. When viewed from a great enough distance, this averages out to "slightly gray". The pound character is made up of around 20 black dots which takes up the same amount of space as the period character -- hence, the effect, when viewed from that critical distance, is a much darker shade of gray.

So, you see, it is necessary for the tiles (or pixels) to be large in order to create the effect of grayness where there is only black and white.

A similar technique is used by printers (i.e. dot-matrix, laser, etc), but because the dot patterns are not constrained to shapes that define a limited set of characters, it can be done more compactly (using something called "Error Diffusion")

BUT, there are two ways to make the image smaller (without altering the code):
1. Reduce the font size.
2. Reduce the size of the original image.
_________________
I came to this planet for it's cheeses and because of Ali Larter
Back to top
View user's profile Send private message
chrp10
Guest





PostPosted: Wed Nov 07, 2007 11:16 am    Post subject: timer/progress bar Reply with quote

hi guys,

can you add a progress bar for this nice tool?

thanks....
Back to top
psych0pat



Joined: 29 Apr 2008
Posts: 4

PostPosted: Fri May 09, 2008 1:42 am    Post subject: ? Reply with quote

Does this part find the grayscale value of the pixel (Or something of that matter)?
Quote:
Code:
    PixelGetColor, found_color, %scan_current_x%, %scan_current_y%
    StringMid, scan_rgb_r, found_color, 3, 2
    StringMid, scan_rgb_g, found_color, 5, 2
    StringMid, scan_rgb_b, found_color, 7, 2
    scan_rgb_r=0x%scan_rgb_r%
    scan_rgb_g=0x%scan_rgb_g%
    scan_rgb_b=0x%scan_rgb_b%
    SetFormat, integer, hex
    scan_rgb_sum:=scan_rgb_r + scan_rgb_g + scan_rgb_b

If so, may I use that bit in my code with credits to you?
If not, what exactly does it do?
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group