Just wanted to share with you a quick tool I did to convert an EidoGo board to a
"text" diagram
The tool is a java application that you start and that will do a copy of the screen and then processes the image to find the goban and render it as text.
Once that done, the "text" is placed into the clipboard ready to be paste where you want, and finally a dialog
is shown to show what as been found.
here is a screenshoot.
[img]http://picshell.ovh.org/go/diagToTxt.jpg[/img]
To use it, you need java to be on your computer, and you need to download the program "DiagToTxt.jar"
(jar stands for Java ARchive).
The file is available here :
http://picshell.ovh.org/go
and download "diagtotxt.jar"
to execute the programme, you need to type the following command (or put it in a .bat file which must be in the smae folder as diagtotxt.jar)
[code]
start javaw -cp diagtotxt.jar oca.DiagToTxt
[/code]
It's really important to start it that way so that no java console is displayed (if the console is displayed,
it may comes in front of the Eidigo diagram and the console will be present in the image...)
Limitation : only work with 19x19 boards.
Enyoy.
for whose who want to see the java code :
[hide][code]package oca;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.plaf.FontUIResource;
public class DiagToTxt {
public static void main(String[] args) throws Exception {
BufferedImage image;
Robot robot = new Robot();
image = robot.createScreenCapture(new Rectangle(Toolkit
.getDefaultToolkit().getScreenSize()));
// String format ="PNG" ;
// ImageIO.write(image, format, new File("screenShot."+format));
// image = ImageIO.read(new File("screenShot."+format));
int startPosY = -1;
int startPosX = -1;
/*
* Find starting point
*/
for (int y = 0; y < image.getHeight(); y++) {
StringBuffer line = new StringBuffer();
for (int x = 0; x < image.getWidth(); x++) {
int clr = image.getRGB(x, y);
if (clr == -2245525) { // = background color "DDBC6B"
line.append("_");
} else {
line.append("X");
}
}
int tmp = line
.toString()
.indexOf(
"___________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________");
if (tmp > -1) {
startPosY = y;
startPosX = tmp;
break;
}
}
int margin = 14;
int nbPixPerSquare = 19;
int py = 0;
StringBuffer goban = new StringBuffer();
goban.append("[go]$$\n");
goban.append("$$ ----------------------------------------\n");
for (int y = startPosY + margin; y < (startPosY + margin + 18
* nbPixPerSquare + 1); y += nbPixPerSquare) {
py++;
goban.append("$$ | ");
for (int x = startPosX + margin; x < (startPosX + margin + 18
* nbPixPerSquare + 1); x += nbPixPerSquare) {
int clr = image.getRGB(x, y - 6);
int red = (clr & 0x00ff0000) >> 16;
int green = (clr & 0x0000ff00) >> 8;
int blue = clr & 0x000000ff;
String r = String.format("%02X%02X%02X", red, green, blue);
int clrCenter = image.getRGB(x, y );
String car = ".";
if (clrCenter==-9412810) {
car = ",";
} else if (r.equals("383838")) {
car = "X";
} else if (r.equals("FEFEFE")) {
car = "O";
}
goban.append(car + " ");
}
goban.append("|\n");
}
goban.append("$$ ----------------------------------------
The tool is a java application that you start and that will do a copy of the screen and then processes the image to find the goban and render it as text.
Once that done, the "text" is placed into the clipboard ready to be paste where you want, and finally a dialog
is shown to show what as been found.
here is a screenshoot.
[img]http://picshell.ovh.org/go/diagToTxt.jpg[/img]
To use it, you need java to be on your computer, and you need to download the program "DiagToTxt.jar"
(jar stands for Java ARchive).
The file is available here :
http://picshell.ovh.org/go
and download "diagtotxt.jar"
to execute the programme, you need to type the following command (or put it in a .bat file which must be in the smae folder as diagtotxt.jar)
[code]
start javaw -cp diagtotxt.jar oca.DiagToTxt
[/code]
It's really important to start it that way so that no java console is displayed (if the console is displayed,
it may comes in front of the Eidigo diagram and the console will be present in the image...)
Limitation : only work with 19x19 boards.
Enyoy.
for whose who want to see the java code :
[hide][code]package oca;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.plaf.FontUIResource;
public class DiagToTxt {
public static void main(String[] args) throws Exception {
BufferedImage image;
Robot robot = new Robot();
image = robot.createScreenCapture(new Rectangle(Toolkit
.getDefaultToolkit().getScreenSize()));
// String format ="PNG" ;
// ImageIO.write(image, format, new File("screenShot."+format));
// image = ImageIO.read(new File("screenShot."+format));
int startPosY = -1;
int startPosX = -1;
/*
* Find starting point
*/
for (int y = 0; y < image.getHeight(); y++) {
StringBuffer line = new StringBuffer();
for (int x = 0; x < image.getWidth(); x++) {
int clr = image.getRGB(x, y);
if (clr == -2245525) { // = background color "DDBC6B"
line.append("_");
} else {
line.append("X");
}
}
int tmp = line
.toString()
.indexOf(
"___________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________");
if (tmp > -1) {
startPosY = y;
startPosX = tmp;
break;
}
}
int margin = 14;
int nbPixPerSquare = 19;
int py = 0;
StringBuffer goban = new StringBuffer();
goban.append("[go]$$\n");
goban.append("$$ ----------------------------------------\n");
for (int y = startPosY + margin; y < (startPosY + margin + 18
* nbPixPerSquare + 1); y += nbPixPerSquare) {
py++;
goban.append("$$ | ");
for (int x = startPosX + margin; x < (startPosX + margin + 18
* nbPixPerSquare + 1); x += nbPixPerSquare) {
int clr = image.getRGB(x, y - 6);
int red = (clr & 0x00ff0000) >> 16;
int green = (clr & 0x0000ff00) >> 8;
int blue = clr & 0x000000ff;
String r = String.format("%02X%02X%02X", red, green, blue);
int clrCenter = image.getRGB(x, y );
String car = ".";
if (clrCenter==-9412810) {
car = ",";
} else if (r.equals("383838")) {
car = "X";
} else if (r.equals("FEFEFE")) {
car = "O";
}
goban.append(car + " ");
}
goban.append("|\n");
}
goban.append("$$ ----------------------------------------
- Click Here To Show Diagram Code
[go] "text" diagram
The tool is a java application that you start and that will do a copy of the screen and then processes the image to find the goban and render it as text.
Once that done, the "text" is placed into the clipboard ready to be paste where you want, and finally a dialog
is shown to show what as been found.
here is a screenshoot.
[img]http://picshell.ovh.org/go/diagToTxt.jpg[/img]
To use it, you need java to be on your computer, and you need to download the program "DiagToTxt.jar"
(jar stands for Java ARchive).
The file is available here :
http://picshell.ovh.org/go
and download "diagtotxt.jar"
to execute the programme, you need to type the following command (or put it in a .bat file which must be in the smae folder as diagtotxt.jar)
[code]
start javaw -cp diagtotxt.jar oca.DiagToTxt
[/code]
It's really important to start it that way so that no java console is displayed (if the console is displayed,
it may comes in front of the Eidigo diagram and the console will be present in the image...)
Limitation : only work with 19x19 boards.
Enyoy.
for whose who want to see the java code :
[hide][code]package oca;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.plaf.FontUIResource;
public class DiagToTxt {
public static void main(String[] args) throws Exception {
BufferedImage image;
Robot robot = new Robot();
image = robot.createScreenCapture(new Rectangle(Toolkit
.getDefaultToolkit().getScreenSize()));
// String format ="PNG" ;
// ImageIO.write(image, format, new File("screenShot."+format));
// image = ImageIO.read(new File("screenShot."+format));
int startPosY = -1;
int startPosX = -1;
/*
* Find starting point
*/
for (int y = 0; y < image.getHeight(); y++) {
StringBuffer line = new StringBuffer();
for (int x = 0; x < image.getWidth(); x++) {
int clr = image.getRGB(x, y);
if (clr == -2245525) { // = background color "DDBC6B"
line.append("_");
} else {
line.append("X");
}
}
int tmp = line
.toString()
.indexOf(
"___________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________");
if (tmp > -1) {
startPosY = y;
startPosX = tmp;
break;
}
}
int margin = 14;
int nbPixPerSquare = 19;
int py = 0;
StringBuffer goban = new StringBuffer();
goban.append("[go]$$\n");
goban.append("$$ ----------------------------------------\n");
for (int y = startPosY + margin; y < (startPosY + margin + 18
* nbPixPerSquare + 1); y += nbPixPerSquare) {
py++;
goban.append("$$ | ");
for (int x = startPosX + margin; x < (startPosX + margin + 18
* nbPixPerSquare + 1); x += nbPixPerSquare) {
int clr = image.getRGB(x, y - 6);
int red = (clr & 0x00ff0000) >> 16;
int green = (clr & 0x0000ff00) >> 8;
int blue = clr & 0x000000ff;
String r = String.format("%02X%02X%02X", red, green, blue);
int clrCenter = image.getRGB(x, y );
String car = ".";
if (clrCenter==-9412810) {
car = ",";
} else if (r.equals("383838")) {
car = "X";
} else if (r.equals("FEFEFE")) {
car = "O";
}
goban.append(car + " ");
}
goban.append("|\n");
}
goban.append("$$ ----------------------------------------[/go]
StringSelection selection = new StringSelection(goban.toString());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
javax.swing.UIManager.put("OptionPane.messageFont", new FontUIResource(
new Font("Courier", Font.PLAIN, 12)));
JOptionPane.showMessageDialog(null,
"DiagToTxt 1.0 by oca\nClipboard content :\n" + goban.toString());
}
}
[/code][/hide]