Sikuli IDE with Fiji(ImageJ)

Asked by Emre Bahtiyar

I am trying write a code on Sikuli IDE to invert a captured image with IJ library. Then I will try to grab the text of that inverted image with Sikuli. Without inverting OCR is not successful (black background, white text).

But I couldn't import IJ to Sikuli. Here is my code:

import shutil
from ij import IJ

OpHp = capture(756,315,143,38)
path = 'C:\\photo\captured.tif'
shutil.copy(OpHp,path)

imp = IJ.openImage(path)
IJ.run(imp, "Invert", "")
IJ.save(imp, 'C:\\photo\captured-inverted.tif')
When I run, it gives: [error] ImportError ( No module named ij ). Is there a way to import it? Or is there any other way to invert an image with Sikuli?

Then I want to grab the text from the inverted image but as far as I know Sikuli only allows to grab text from a region with:

myRegion.text()
command. Is there a way to grab the text of an image (not of a region) with Sikuli?

Thanks in advance.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Emre Bahtiyar
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

as far as a quick look into the tutorials of ImageJ2 tells me:

- have the relevant ImageJ jar on class path at runtime

# in the script:
import net.imagej.ImageJ as ImageJ;
#....
ij = ImageJ();

now ij gives you access to all features available in package net.imagej.ImageJ

For specific features it might be necessary to add additional imports and instantiate additional objects.

start here:
https://github.com/imagej/imagej-tutorials/blob/master/intro-to-imagej-api/src/main/java/IntroToImageJAPI.java

Revision history for this message
Emre Bahtiyar (emrey) said :
#2

I am a noob so I couldn't find any ImageJ jar named liked that and all the others I tried didn't work. I migrate to full java coding with netbeans. I added sikulixapi.jar to my libraries. I made image color inverting on the pixel level with java.

Evertything is easier and better for me this way but...

At the end of my original question I asked that is there a way to grab the text from an image which is located on the harddrive. I inverted and created a new file from what I captured with Sikuli. Now I a trying to get text from the file which is lets say in the path "c:\img\test.png" but couldn't do it. Is it possible??

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Sorry, missed that.

No, currently there is no feature to read text from an image.

2 possibilities:
- open it in a an image viewer and use Region.text()
- install Tesseract and use the Tesseract command to convert the image to text

I will add this feature to the final 1.1.0, which is under development currently.

Revision history for this message
Emre Bahtiyar (emrey) said :
#4

I was avoiding the first one you proposed but the second one I will try with my limited knowledge.

Revision history for this message
RaiMan (raimund-hocke) said :
#5

If this might be an alternative:
I just added the feature to the version 1.1.0 (sikulix.com -> nightly build: build 1.1.0 2014-09-12+ - which means tomorrow)

simplest usage:
String containedText = Image.text("some_image.png")

where some_image.png is your modified image file.

Revision history for this message
Emre Bahtiyar (emrey) said :
#6

That is very good news for me because it seems like tess4j+jdk 64bits+ netbeans+64 bit windows 7 is not good mixture.

Added 64 bit dlls and tried so many things but still no luck (UnsatisfiedLinkError for libtesstesseract302) .

I will try the new feature tomorrow and I believe it will be a good additional feature for Sikuli.

Thank you again for all your efforts.