Skip to content

Commit

Permalink
working on linux portability
Browse files Browse the repository at this point in the history
  • Loading branch information
Arxa authored and Arxa committed Mar 4, 2018
1 parent cdc57fd commit 2473d1a
Show file tree
Hide file tree
Showing 32 changed files with 45 additions and 52 deletions.
16 changes: 9 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ dependencies {
compile group: 'com.google.guava', name: 'guava', version: '23.3-jre'
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'

// Tesseract - OCR
// Tesseract - ocr
compile group: 'org.bytedeco.javacpp-presets', name: 'tesseract', version: '3.04.01-1.3'
compile group: 'org.bytedeco.javacpp-presets', name: 'tesseract', version: '3.04.01-1.3', classifier: opencvBinaryClassifer
compile group: 'org.bytedeco.javacpp-presets', name: 'leptonica', version: '1.73-1.3', classifier: opencvBinaryClassifer
Expand All @@ -89,11 +89,13 @@ test {
testLogging.showStandardStreams = true
}

jfx {
jfx{
verbose = true
appName = "VideoText Extractor"
mainClass = 'Main'
vendor = 'arxa'
bundler = 'windows.app'
bundleArguments = [
'runtime': 'C:\\Program Files\\Java\\jdk1.8.0_144\\jre'
]
vendor = 'Nikiforos Archakis'
//bundler = 'windows.app'
// bundleArguments = [
// 'runtime': 'C:\\Program Files\\Java\\jdk1.8.0_144\\jre'
// ]
}
File renamed without changes
27 changes: 20 additions & 7 deletions src/main/java/controllers/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import entities.ApplicationPaths;
import entities.Controllers;
import entities.OutputFolderNames;
import javafx.application.Platform;
import javafx.scene.control.Button;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextArea;
import processors.FileProcessor;
import processors.Player;
import processors.VideoProcessor;
Expand All @@ -22,12 +24,16 @@
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
import org.apache.commons.io.FilenameUtils;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Timer;
import java.util.TimerTask;

import static java.awt.Desktop.getDesktop;

public class MainController
{
public Pane videoPane;
Expand All @@ -47,7 +53,7 @@ public class MainController
public Button decreaseFont_button;
public MenuItem outputImagesMenuItem;

private static File currentVideoFile;
private static File currentVideoFile = new File("nofile");
private static Stage mainStage;

public void initialize()
Expand All @@ -60,10 +66,15 @@ public void initialize()
processButton.setCursor(Cursor.HAND);

outputImagesMenuItem.setOnAction(event -> {
try {
Runtime.getRuntime().exec("explorer.exe " + ApplicationPaths.RESOURCES_OUTPUTS);
} catch (IOException e) {
MainController.showError("Failed to open file explorer; "+e.getMessage());
if( Desktop.isDesktopSupported() )
{
new Thread(() -> {
try {
Desktop.getDesktop().open(new File(ApplicationPaths.RESOURCES_OUTPUTS));
} catch (IOException e) {
showException(e);
}
}).start();
}
});

Expand Down Expand Up @@ -143,6 +154,8 @@ public void initialize()
closeVideo.setOnAction(event -> {
VideoProcessor.checkThreadStatus();
Player.stopMediaPlayer();
ApplicationPaths.UNIQUE_OUTPUT_FOLDER_NAME = "";
setCurrentVideoFile(new File("nofile"));
videoPane.getChildren().clear();
videoPane.getChildren().add(videoIcon);
videoIcon.setVisible(true);
Expand Down Expand Up @@ -203,7 +216,7 @@ public void run() {
}

/**
* Initializes FXML loaders and controllers of other Views
* Initializes FXML loaders and controllers of other views
*/
public void initializeViews(){
try {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/controllers/SettingsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public void initialize() throws IOException

moreLanguagesLabel.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
// Showing an alert with a clickable hyperlink inside
Alert alert = new Alert(Alert.AlertType.INFORMATION, "Download the .traineddata language files(s) you wish to add from the following link and place the file(s) project's directory: src\\main\\resources\\OCR\\tessdata");
Alert alert = new Alert(Alert.AlertType.INFORMATION, "Download the .traineddata language files(s) you wish to add from the following link and place the file(s) project's directory: src\\main\\resources\\ocr\\tessdata");
alert.setTitle("How to add more languages");
FlowPane fp = new FlowPane();
Label lbl = new Label("Download the .traineddata language files(s) you wish to add from the following link \n" +
"and place the file(s) in the project's directory: OCR\\tessdata \n" +
"and place the file(s) in the project's directory: ocr\\tessdata \n" +
"Restart the application and you should see the new language options in Tools->Settings");
Hyperlink link = new Hyperlink("https://github.com/tesseract-ocr/tessdata/tree/3.04.00");
link.addEventHandler(MouseEvent.MOUSE_CLICKED, event1 -> {
Expand All @@ -76,15 +76,15 @@ public void initialize() throws IOException
languageMap.put(tokens[1],tokens[0]);
}

// Check which traineddata files exist in the tessdata directory and make that language(s) available to the OCR languages combobox.
// Check which traineddata files exist in the tessdata directory and make that language(s) available to the ocr languages combobox.
Collection files = FileUtils.listFiles(new File(ApplicationPaths.RESOURCES_OCR_TESSDATA), null, false);
for(Object f : files){
if (languageMap.values().contains(((File)f).getName().split("\\.")[0])){
ocrLanguage_combobox.getItems().add(getKeyByValue(languageMap,((File)f).getName().split("\\.")[0]));
}
}

// Set default OCR language selection to English
// Set default ocr language selection to English
ocrLanguage_combobox.getSelectionModel().select("English");

// Saves the characters that are being typed in the checkbox's list and jumps you to the matching language
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/entities/ApplicationPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ApplicationPaths
public static String RESOURCES_MODELS;
public static String RESOURCES_ICONS;
public static String RESOURCES_CSS;
public static String UNIQUE_OUTPUT_FOLDER_NAME = "invalid-for-now";
public static String UNIQUE_OUTPUT_FOLDER_NAME = "";

/***
* Sets the application's directory paths differently whether it is a JAR file calling or an IDE
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/processors/FileProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ else if(SystemUtils.IS_OS_LINUX){
Controllers.getLogController().logTextArea.appendText("32-bit Linux not supported yet\n");
}
else if (bit == 64){
System.load(Paths.get(ApplicationPaths.RESOURCES_NATIVES,"opencv_320_64.so").toString());
System.load(Paths.get(ApplicationPaths.RESOURCES_NATIVES,"libopencv_320_64.so").toString());
Controllers.getLogController().logTextArea.appendText("Loaded OpenCV for Linux 64 bit\n");

System.load(Paths.get(ApplicationPaths.RESOURCES_NATIVES,"openh264-1.6.0-linux64.3.so").toString());
System.load(Paths.get(ApplicationPaths.RESOURCES_NATIVES,"libopenh264-1.6.0-linux64.3.so").toString());
Controllers.getLogController().logTextArea.appendText("Loaded OpenH264 for Linux 64 bit\n");
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/processors/OcrProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class OcrProcessor
public static void initializeOcr(tesseract.TessBaseAPI ocrApi) throws Exception {
if (ocrApi.Init(ApplicationPaths.RESOURCES_OCR, SettingsController.getLanguageMap().
get(Controllers.getSettingsController().ocrLanguage_combobox.getSelectionModel().getSelectedItem().toString())) != 0) {
throw new Exception("Failed to set OCR language!");
throw new Exception("Failed to set ocr language!");
}
/*if (!Controllers.getSettingsController().includeSpecialCharacters_checkbox.isSelected()){
ocrApi.SetVariable("tessedit_char_blacklist", "`,#[];()!£\"$%^&\\²³²£§¶¤°¦<>|€");
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/processors/VideoProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void processVideoFile(File videoFile)
{
@Override protected Void call()
{
// OCR Initialization
// ocr Initialization
uniqueWords = new ArrayList<>();
tesseract.TessBaseAPI ocrApi = new tesseract.TessBaseAPI();
try {
Expand Down Expand Up @@ -154,7 +154,7 @@ default value (-1, -1) means that the anchor is at the element center.
// Write painted frame to video
videoWriter.write(inputWithTextBlocks);

// Preprocess textblocks and extract text with OCR
// Preprocess textblocks and extract text with ocr
if (Controllers.getSettingsController().extractTextCheckBox.isSelected()){
for (Mat textBlock : ImageProcessor.getCroppedTextBlocks(textBlocks)){
File ocrImageFile = preprocessTextBlock(textBlock);
Expand Down Expand Up @@ -226,7 +226,7 @@ default value (-1, -1) means that the anchor is at the element center.


/**
* Preprocesses the text blocks, before proceeding to OCR, in order
* Preprocesses the text blocks, before proceeding to ocr, in order
* to achieve better extraction results
* @param textBlock List of image's text blocks in Rect format
*/
Expand Down
22 changes: 0 additions & 22 deletions src/main/resources/CSS/RootLayout.css

This file was deleted.

Loading

0 comments on commit 2473d1a

Please sign in to comment.