Compile OpenCV 3.1 And Python 2.7 With CUDA 7.5 On Ubuntu 14.04

COMPILE OPENCV 3.1 AND PYTHON 2.7 WITH CUDA
ref:http://rolflussi.blogspot.co.id/2015/09/opencv-with-cuda-on-ubuntu-1404.html
1. Create a new virtualenv with python parameter point to python2.7.

2. Check python version:

3. Check pip version:

4. Install numpy:

CHECK numpy VERSION:

IMPORTANT: I FOUND AN ERROR ‘The data should normally be NULL! in function allocate’ WHEN TRY TO TEST SIFT Holography Feature Matching (flann.knnMatch). PLS FIX THIS FIRST (SEE SOLUTION IN /media/data/MASTER/opencv/github_list_fish_rec.txt) BEFORE BUILD OPENCV AT STEP #5 BELOW! — OKAY. THIS IS ALREADY FIXED ON THE LAST COMPILE (OPENCV 3.1 WITH PYTHON 2.7)

5. We already cloned opencv 3.1.0 and opencv_contrib 3.1.0. so now, go to the build WITH CUDA and do setup:
<OLD>
THIS IS THE INITIAL CMAKE COMMAND: (DONT USE IT!)

</OLD>

<OLD>
THIS IS THE CMAKE COMMAND WITH CUDA I GOT FROM http://rolflussi.blogspot.co.id/2015/09/opencv-with-cuda-on-ubuntu-1404.html: (DONT USE IT! ‘WITH_QT’ COMMAND GAVE ME AN ERROR! MAY BE I DONT HAVE QT INSTALLED)

THIS IS THE ERROR:

</OLD>

<NEW>
THIS IS THE CMAKE COMMAND WITH CUDA AND REMOVE ‘WITH_QT’ COMMAND. THIS IS WORK!!! BUT MAKE SURE ‘build’ directory EMPTY FIRST!
NOTE: I USE ‘INSTALL_C_EXAMPLES=ON’ INSTEAD OF ‘OFF’ LIKE PREVIOUS BUILD. LET ME KNOW IF EVERYTHING WORKS (ITS CONFIRMED!!!)

</NEW>

NOTE:
PLS SEE THE NVIDIA CUDA PART ON THE ABOVE RESULT IS INCLUDED! BUILD WITH CUDA IS FAST (A FEW MINUTES)!

6. Compile opencv:
NOTE: BEFORE EXECUTING THIS, CONSIDER TO EDIT THIS FILE:

SEE BELOW HOW TO MODIFY IT!!!

NOTE:
AFTER WAITING FOR MORE THAN 1 hour AND 25 MINUTES (91% COMPLETED), THE COMPILATION IS STOPPED WITH THESE ERRORS STACK:

SOLUTION:
ref:https://github.com/Itseez/opencv/issues/5859
I USED A TEMPORARY SOLUTION: EDIT /home/teddy/opencv/build/samples/gpu/CMakeFiles/example_gpu_opengl.dir/link.txt. THEN ADD THIS: -lGL -lGLU AT THE END OF THE LINE (IN SINGLE LINE! DONT ADD AT THE NEW LINE!). SO THE FILE WOULD BE LIKE THIS:

SAVE THE FILE THEN RE-MAKE (BUT I SUGGEST TO REMOVE ‘build’ DIRECTORY, CREATE IT AGAIN LIKE STEP #5. BUT BEFORE EXECUTING STEP #6, EDIT link.txt FILE LIKE THE ABOVE! ). THIS SOLUTION IS WORKING!!!
ACTUALLY THERE IS A PERMANENT SOLUTION IS SUGGESTED IN THE SAME URL, BUT I DONT KNOW HOW TO DO IT!!! LEARN IT

OK. HERE IS THE SUCCESFULL COMPILE (MAKE)

NOTE:
SEE THE MORE COMPLETE COMPILATION (MAKE) PROCESS IN THIS FILE: /media/data/MASTER/opencv/make_opencv_cuda.txt
ITS NOT FULL COMPLETED BECAUSE I MISSED SOME DATA BUT IT WORTHS TO SEE (THERE ARE SOME WARNING!!!)
THIS COMPILATION TOOK MORE THAN 1 hour AND 30 MINUTES. COMPILATION WITH CUDA (MAY BE ALSO WITH OPENGL) MAKE IT SLOWER!!!

WARNINGS:
1.

2.

7. Assuming OpenCV 3.1 compiled without error, you can now install it on your system:
NOTE: BEFORE EXECUTING THIS COMMAND, MODIFY AGAIN THE ABOVE FILE: /home/teddy/opencv/build/samples/gpu/CMakeFiles/example_gpu_opengl.dir/link.txt OR WE’D GET THE SAME ERROR (PLS SEE THE ERROR HERE: /media/data/MASTER/opencv/opencv_cuda_make_install_error.txt ):

THIS TIME WE MUST USE SUDO BECAUSE THE FILE IS LOCKED:

THEN ADD THIS AT THE END OF THE SINGLE LINE LIKE ABOVE: -lGL -lGLU
THEN SAVE AND CLOSE
INSTALL AGAIN:

NOTE:
FOR COMPLETE PROCESS RESULT, SEE THIS FILE: /media/data/MASTER/opencv/opencv_cuda_make_install_success.txt

8.

9. If you’ve reached this step without an error, OpenCV should now be installed in /usr/local/lib/python2.7/site-packages
However, our ‘opencv_p27_cuda’ virtual environment is located in our home directory — thus to use OpenCV within our cv environment, we first need to sym-link OpenCV into the site-packages directory of the ‘opencv_p27_cuda’ virtual environment:

10. Check the installation opencv version:

11. EXECUTE SOME OPENCV EXAMPLES in /home/teddy/opencv/build/bin/ DIRECTORY:
a. Run this example (image grain):

b. Test Cuda Codec:

 

Installation of CUDA Toolkit 7.5 On Ubuntu 14.04

CONSIDER USING CUDA???
FROM THIS: https://en.wikipedia.org/wiki/CUDA, MY GPU Nvidia GeForce GT 520M IS SUPPORTED!!! Micro Architecture Fermi (https://en.wikipedia.org/wiki/Fermi_(microarchitecture)) version 2.1
CHECK CUDA FROM TERMINAL:
ref:http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/#axzz44a7lZNcT

INSTALLING CUDA TOOLKIT 7.5 ON UBUNTU 14.04
ref:http://www.r-tutor.com/gpu-computing/cuda-installation/cuda7.5-ubuntu
https://www.quantstart.com/articles/Installing-Nvidia-cuda-on-Ubuntu-14-04-for-Linux-GPU-Computing
https://developer.nvidia.com/cuda-downloads -> Linux -> x86_64 -> Ubuntu -> 14.04 -> deb(local)
http://developer.download.nvidia.com/compute/cuda/7.5/Prod/local_installers/cuda-repo-ubuntu1404-7-5-local_7.5-18_amd64.deb
(1.9 GB)
1. The first task is to make sure that you have the GNU compiler collection (GCC) tools installed. This is carried out by installing the build-essential package:

2. Download the latest Cuda toolkit:
Manually FROM:
http://developer.download.nvidia.com/compute/cuda/7.5/Prod/local_installers/cuda-repo-ubuntu1404-7-5-local_7.5-18_amd64.deb
OR:

3. PREPARE THE PACKAGE:

OK

4. Update

5. INSTALL CUDA:

SOLUTION:
ref:http://askubuntu.com/questions/672047/anyone-has-successfully-installed-cuda-7-5-on-ubuntu-14-04-3-lts-x86-64

RUN AGAIN:

6. REBOOT

7. MODIFY ENVIRONMENT VARIABLES:
As part of the CUDA environment, you should add the following in the .bashrc file of your home folder.

ADD THESE LINES AT THE BOTTOM:

THEN SAVE AND CLOSE!

8. Remember to make sure that the terminal has access to these variables:

9. Before proceeding to test the GPU cards we will ensure that the drivers are correctly installed. The following line will provide us with the driver version:

10. Check the version of the Nvidia CUDA compiler:

TRY THE CUDA 7.5 SAMPLES:
1. Copy the samples into /home/teddy/Documents/

2. GO to the samples directory:

3. Go to the deviceQuery directory THEN make:

4. run the deviceQuery script to test if we can communicate with the GPU:

 

5. Go to the bandwidthTest directory THEN make:

 

6. run bandwidthTest:

 

Installation of OpenCV, Keras and Tensorflow On Ubuntu 14.04

Reference: http://www.pyimagesearch.com/2016/11/14/installing-keras-with-tensorflow-backend/
step-by-step instructions to install Keras using a TensorFlow backend for machine learning.

Keras is simply a wrapper around more complex numerical computation engines such as TensorFlow and Theano.

When it comes to Keras you have two choices for a backend engine — either TensorFlow or Theano. Theano is older than TensorFlow and was originally the only choice when selecting a backend for Keras.

So why might you want to use TensorFlow over Theano?

The short version is that TensorFlow is extremely flexible, allowing you to deploy network computation to multiple CPUs, GPUs, servers, or even mobile systems without having to change a single line of code.

This makes TensorFlow an excellent choice for training distributed deep learning networks in an architecture agnostic way, something that Theano does not (currently) provide.

Installation:

  1. Use Python virtual environments.

    You can quit the virtualenv with command ‘deactivate’

    And go back the virtualenv with command ‘workon opencv_keras_tf’

    Check python version:

     
  2. Install TensorFlow
    NOTE: Read this about CUDA compute capability : http://stackoverflow.com/questions/10961476/what-are-the-differences-between-cuda-compute-capabilities
    IT SEEMS DEPEND ON THE HARDWARE! NOTHING CAN DO TO IMPROVE THE COMPUTE CAPABILITY!
    AFTER READING THIS https://www.tensorflow.org/versions/r0.10/get_started/os_setup#installing_from_sources AND http://stackoverflow.com/questions/38542763/how-can-i-make-tensorflow-run-on-a-gpu-with-capability-2-0, I GOT SAD NEWS THAT
    In order to build or run TensorFlow with GPU support, both NVIDIA’s Cuda Toolkit (>= 7.0) and cuDNN (>= v3) need to be installed.
    TensorFlow GPU support requires having a GPU card with NVidia Compute Capability >= 3.0.
    SO MY GPU GeForce GT 520M THAT ONLY HAS CUDA COMPUTE CAPABILITY 2.1 (REF: https://en.wikipedia.org/wiki/CUDA) CAN’T BE USED FOR TENSORFLOW!!!I ONLY CAN USE CPU!!!To install TensorFlow, refer to this page: https://www.tensorflow.org/versions/r0.11/get_started/os_setup.
    Currently I have CUDA 7.5 toolkit installed

    The tensorflow page need CUDA toolkit 8.0 and CuDNN v5. I already installed them. I go to ‘Pip installation’ and choose this binary option:

    SO let’s begin:

    Install TensorFlow:

    Test the installation

     
  3. Install Keras
    Install a few Python dependencies:
    Install numpy scify

    Install scikit-learn

    Install pillow

    Install h5py

    Install keras

    Then run ‘import keras’ in python console to create keras.json file (http://stackoverflow.com/questions/40310035/how-to-change-keras-backend-wheres-the-json-file)

    keras.json file would be created in ~/.keras/ (~/.keras/keras.json file)

    Specifically, you’ll want to ensure that image_dim_ordering  is set to tf  (indicating that the TensorFlow image dimension ordering is used rather than th  for Theano).

    You’ll also want to ensure that the backend  is properly set to tensorflow  (rather thantheano ).

  4. Symlink with OpenCV
    My opencv binding file for python 3 is in /usr/local/lib/python3.4/site-packages/cv2.cpython-34m.so. I need to symlink it with the virtualenv ‘opencv_keras_tf’ like this:
    Go into this directory:

    Then symlink it (HERE I CHANGE THE FILE TO ‘cv2.so’)

    Test it

    OK. NO ERROR

Phalcon Developer Tools on Linux

Reference: https://docs.phalconphp.com/en/latest/reference/linuxtools.html

Developer Tools
These tools are a collection of useful scripts to generate skeleton code. Core components of your application can be generated with a simple command, allowing you to easily develop applications using Phalcon.
Make sure the phalcon module already installed.

Installation of Phalcon Developer Tools for Linux:

  1. Clone the tools
  2. Go into the directory then execute ”. ./phalcon.sh”, (don’t forget the dot at beginning of the command):

    At the end I got an error “ERROR: Phalcon extension isn’t installed…”. This is may be because my php cli version (php version 7) is different with my default php (php version 5.6). From the previous article, I only install phalcon for php 5.6. So change the php version for cli (read again http://myprojects.advchaweb.com/index.php/2016/09/16/update-ppa-for-php/) like this:

    When I did the last error command, it’s working now

     
  3. Create a symbolink link to the phalcon.php script:

    I think ‘phalcon’ can be used from everywhere now. even I don’t need to execute this command anymore

    Here is the ‘phalcon’ command running at home directory:

     

Use Phalcon Developer Tools for Projects (ref: https://docs.phalconphp.com/en/latest/reference/tools.html):

  1. Create a project
    Note: To enable the web tools (for web GUI) , add the ‘–enable-webtools’ after the project name

    SO it just not ‘phalcon create-project store’
  2. Open it on your browser (http://localhost/works/phalcon/store/). But I got this error:

    From this forum: https://forum.phalconphp.com/discussion/15389/volt-directory-cant-be-written, I tried to modify the files permission to ‘664’

    Then refresh, got another error:

    Now try to modify to ‘777’.

    Then refresh again AND IT’S WORKING NOW (http://localhost/works/phalcon/store/)

    The web tools (make sure you create your project with the webtools enabled)
    Open it on your browser http://localhost/works/phalcon/store/public/webtools.php. If you get the display like thisIt means the css and js file can’t be loaded properly. From this link: https://forum.phalconphp.com/discussion/15111/webtools-can-not-load-css-if-using-different-baseuri, I need to modify /app/config/config.php and add ‘staticUri’ like this:

    Then refresh again your browser (http://localhost/works/phalcon/store/public/webtools.php), Here is the displayNOTE: I FOUND ONLY ‘controller’ COMMAND IS WORKING, BUT ‘model’ and ‘scaffold’ COMMANDS IS NOT WORKING! I ALSO TRIED THE COMMAND LIKE ‘phalcon model products’ AND IT DON’T WORK. I THINK THE PROBLEM IN THE DEV TOOLS! I put this issue in phalcon github (https://github.com/phalcon/phalcon-devtools/issues/976): Cannot create model via devtools but can create controller
    “I can create controller via the devtools (and webtools) but I can’t create model. Here is the command:

    $ phalcon model products

    The result:

    Phalcon DevTools (3.0.4)
    Error: Table “products” does not exist.

    I also can’t do it via webtools. I fill the form like the table name and click ‘Generate’. The weird thing happened. it said ‘Models were created successfully’ but I see nothing.

    I also found the url for the webtools is a bit weird (it’s working though). when I opened it the first time, the url is like this: http://localhost/works/phalcon/store/public/webtools.php
    but after i clicked the others links (do some stuff on controllers, models, system info, etc), the ‘/webtools.php/’ keep added and make the url longer, so it’d be like this: http://localhost/works/phalcon/store/public/webtools.php/webtools.php/webtools.php/webtools.php/webtools.php?_url=/controllers/list.

    Info:
    Phalcon DevTools Version: 3.0.4
    Phalcon Version: 3.0.3
    AdminLTE Version: 2.3.6
    OS: Linux teddy-K43SJ 4.4.0-62-generic #83 14.04.1-Ubuntu SMP Wed Jan 18 18:10:30 UTC 2017 x86_64
    PHP Version: 5.6.30-1+deb.sury.org~trusty+1
    PHP SAPI: apache2handler”
    I’M WAITING THE ANSWER!!!

    Test Phalcon (https://docs.phalconphp.com/en/latest/reference/tools.html)
    Generating Controllers

    The command “create-controller” generates controller skeleton structures. It’s important to invoke this command inside a directory that already has a Phalcon project.

    This is the content of /store/app/controllers/TestController.php

    Modify the above controller like this:

    Then open it on your browser: http://localhost/works/phalcon/store/test
    Result of the test controller:
    Create a new database ‘phalcon_store’ (via phpmyadmin)
    Preparing Database Settings
    When a project is generated using developer tools. A configuration file can be found in app/config/config.php (NOT config.ini file).

    To generate models or scaffold, you will need to change the settings used to connect to your database. I CAN’T USE DEVTOOL FOR CREATING MODEL LIKE I SAID ABOVE, SO I’LL DO IT MANUALLY! SO create a new file ‘Products.php’ in /app/models/ directory. I also added setter/getter methods

    SCAFFOLD ALSO SEEMS DONT WORK VIA DEVTOOLS!

    SO FOR SAVING TIME, I DOWNLOAD THE WORKING CODE FROM https://github.com/gsokolowski/ph-store. –> THE LOOKS STILL SAME WITH MINE. NO DIFFERENT. ONLY SHOW ‘Congratulation.
    HERE IS LOCAL PHALCON PROJECT WORKING: http://localhost/works/phalcon/invo. –>LEARN THIS!

    NOTES:
    I found when the first time the page is loaded (index.php in /public/ dir), it’d be referred to /app/views/index.volt. then content “{{ content }}” would be picked up from /app/views/index/index.volt. We can modify this file to change the frontend content

    Here is the looks (http://localhost/works/phalcon/store/)

     

Phalcon Compilation and Installation on Ubuntu 14.04

Reference: https://phalconphp.com/en/download
How To Install Phalcon PHP Framework on Ubuntu 14.10, 14.04 & 12.04
Phalcon is a C extension, so you need to download a binary for your platform or compile it from source code (SO INSTALL THE BINARY OR COMPILE! CHOOSE ONLY OF THEM!).
Installation on Ubuntu 14.04:

Install the binary (the easiest way but it don’t mean it’d be working!)

Install the package

SO the installation is failed! I got the above error. May be because Ubuntu 14.04 has not been supported yet (https://forum.phalconphp.com/discussion/6217/ubuntu-cant-install-phalcon). SO IT’S TIME TO COMPILE THE SOURCE!
But before installing the source, we need some required packages. Check those packages if they haven’t been installed in your machine. My ubuntu 14.04 already has ‘python-software-properties’, ‘software-properties-common’, ‘php5-dev’, ‘php5-mysql’, ‘gcc’ and ‘libpcre3-dev’. So now I just need to compile the phalcon source code:

  1. Clone the phalcon code
  2. Go into the ‘cphalcon/build’ directory

     
  3. then install

    OK. It takes a while to install it. It recommended to install apache web server.
  4. Then Create phalcon.ini file in /etc/php/5.6/mods-available/ directory (because I use php 5.6)

    Then type ‘extension=phalcon.so’ (WITHOUT QUOTE!)
    That mean we can use ‘phalcon’ in PHP 5.6 ONLY! TO enable the mod in the others php version, we can use the same method!
    No need to use command ‘sudo phpenmod phalcon’ anymore!
    NOTE: Somehow I can’t use this command instead of the above

    I also tried to write the extension directly in ‘/etc/php/5.6/apache2/php.ini’ but apache showed error when trying to restart it!
  5. Then restart the apache web server

    If there is no error, then check it on php_info()I CAN ALSO CHECK THE MODULES INSTALLED FROM COMMAND TERMINAL:

    SO COMPILATION AND INSTALLATION SUCCESS!
    TO TRY AND LEARN PHALCON DEEPER (CMS, BLOG, LOGIN, ETC), THIS IS A GOOD COMPILATION: https://github.com/sergeyklay/awesome-phalcon.

Removing Old Kernel of Ubuntu 14.04 Safely

References:  https://help.ubuntu.com/community/RemoveOldKernels
http://blog.dustinkirkland.com/2016/06/purge-old-kernels.html
http://www.webupd8.org/2016/07/how-to-safely-remove-old-linux-kernels.html

My current running kernel:

List of all kernel I have:

Oh man. My machine still keep the kernel 3.xx.xx. It’s already version 4.4.x now! I need to remove the old ones. I got this command ‘sudo purge-old-kernels’ can remove them. The website says:
“purge-old-kernels will remove old kernel and header packages from the system, freeing disk space. It will never remove the currently running kernel. By default, it will keep at least the latest 2 kernels, but the user can override that value using the –keep parameter. Any additional parameters will be passed directly to apt-get(8).”
But first update my system and install ‘bikeshed’

then run ‘sudo purge-old-kernels’ command! (NOTE: READ THE KERNELS LISTED FIRST BEFORE TYPING ‘Y’ TO DELETE THEM! BE CAREFUL! CREATE A BACKUP FIRST!!!)

THE LAST KERNEL WOULD BE REMOVED IS ‘4.4.0-59’. My current kernel version is ‘4.4.0-62’. IT SAID WOULD FREE MY DISK SPACE FOR 10.7 GB!!!
IF YOU SURE, TYPE ‘Y’. HERE IS THE LAST PROCESS I CAN CAPTURE

OK. NOW My disk space is 16.8GB FROM 3.5GB!
RUN UPDATE AFTER THE PROCESS IS FINISHED. RESTART IF NEEDED.

 

 

Installing Tesseract OCR on Ubuntu 14.04

Reference: https://github.com/tesseract-ocr/tesseract/wiki/Compiling
http://hanzratech.in/2015/01/16/ocr-using-tesseract-on-ubuntu-14-04.html

Compilation:

  1. clone the package from github
  2. Go to the new dir
  3. autogen
  4. configure

    Here i can’t configure it correctly because it always complained about leptonica 1.74

    I already did

    But the error still persist!
    SOLUTION: I HAVE TO COMPILE AND INSTALL LEPTONICA 1.74 MANUALLY (READ: http://myprojects.advchaweb.com/index.php/2017/02/02/installing-leptonica-1-74-1-on-ubuntu-14-04/)
    NOW IT SUCCESS!

     
  5. Since we have to compile leptonica to use version 1.74, we should use LDFLAGS=”-L/usr/local/lib” CFLAGS=”-I/usr/local/include” make instead of make for Tesseract.

     
  6. make install

     
  7. sudo ldconfig

     
  8. Make training

     
  9. Install the training

    For the training tutorial, pls read: https://github.com/tesseract-ocr/tesseract/wiki/TrainingTesseract-4.00 (OR https://github.com/tesseract-ocr/tesseract/wiki/Training-Tesseract for older tesseract version). It says it use neural network-based recognition engine. ALSO “Tesseract 4.00 takes a few days to a couple of weeks. Even with all this new training data, you might find it inadequate for your particular problem, and therefore you are here wanting to retrain it.”. IT’D TAKE A FEW DAYS – WEEKS??? IT SEEMS SAME WITH TRAINING OPENCV. IF I HAVE PLENTY OF TIME I CAN DO THAT. ACTUALLY IT’S INTERESTING!
  10. For visual debugging, build ScrollView.jar

    Export ‘SCROLLVIEW_PATH’:

     

     

  11. Install Language
    For example to install english and many other files, pls see https://github.com/tesseract-ocr/tesseract/wiki/Data-Files. I downloaded english language https://sourceforge.net/projects/tesseract-ocr-alt/files/tesseract-ocr-3.02.eng.tar.gz/download.
    <OLD>Then extract the zip file ‘tesseract-ocr-3.02.eng.tar.gz’. then move all files in /tesseract-ocr/tessdata/ to /tesseract/tessdata/
    DONT FORGET TO POINT OUT ‘TESSDATA_PREFIX’!

    </OLD>
    <NEW>It’d be much better to copy/move the ‘tessdata’ directory into /usr/local/share/tessdata/ than copy/move them into /cpp/tesseract/tessdata/ above (the OLD> because we dont have to type ‘export TESSDATA_PREFIX…’ everytime we need to scan an image. I did this after did the old one

    </NEW>
    AT FIRST I FORGOT ABOUT THIS. WHEN I DID A TEST, HERE IS THE MESSAGE
  12. Check tesseract version (with -v or –version)

     
  13. Test!

    Here is the image source (‘phototest.tif’) And here is the result in /tesseract/output.txt

    NOTE : IT BETTER TO NOT USE FILENAME WITH HAS SPACE BECAUSE TESSERACT CAN’T FIND IT!
    ALSO USE IMAGE WITH HIGH RESOLUTION! OR WE CAN DO THE TRAINING STUFF (IF WE HAVE PLENTY OF TIME!!!)
    OTHER TESTS

    BUT I FOUND THE RESULT STILL NOT GOOD!!! MANY WEIRD CHARS, SPELLING MISTAKES,ETC
    ANOTHER TEST WITH COMMAND TERMINAL:

    Display the result in the terminal:

    open the original image so we can compare it

     
  14. Question: Can we use tesseract to read/scan pdf file?
    pls read: http://kiirani.com/2013/03/22/tesseract-pdf.html
    http://www.barryhubbard.com/linux/converting-pdf-to-text-using-tesseract/
    http://stackoverflow.com/questions/30925218/converting-a-pdf-to-text-using-tesseract-ocr
    TESSERACT CAN’T DO THIS DIRECTLY. IT SAID TO CONVERT THE PDF TO TIFF IMAGE FIRST! ALSO THE MULTI PAGE PDF NEED TO BE CONVERTED TO MULTI TIFF FILES! READ http://www.barryhubbard.com/linux/converting-pdf-to-text-using-tesseract/ TO SEE THE SCRIPT TO DO THAT!

Installing Leptonica 1.74.1 on Ubuntu 14.04

Reference: http://hanzratech.in/2015/01/16/ocr-using-tesseract-on-ubuntu-14-04.html
http://www.leptonica.org/download.html

  1. Download the newest leptonica version (1.74.1) here : http://www.leptonica.org/source/leptonica-1.74.1.tar.gz
    I use wget:


     
  2. Extract the zip file
  3. Go to the new created directory (leptonica-1.74.1) then configure

     
  4. make

     
  5. Because my machine didn’t have ‘checkinstall’, install it first

     
  6. Create the package with ‘checkinstall’

     
  7. Then execute ‘sudo ldconfig’

     

PHP Tools

Install some PHP tools:

  1. PHP Coding Standards Fixer (http://cs.sensiolabs.org/)
    Installation: (Globally (Composer))

    Then make sure you have ~/.composer/vendor/bin in your PATH and you’re good to go:

    To find out the location of php-cs-fixer

    I can use the location for the netbeans plugins needed.
    Another reference: https://mattstauffer.co/blog/using-php-cs-fixer-to-fix-up-your-php-code
  2. PHP CodeSniffer
    Ref: http://purencool.com/install-and-test-phpcodesniffer-on-ubuntu
    http://askubuntu.com/questions/572956/adding-a-standard-to-php-codesniffer
    Installation:

    To find out the location

    To verify PHP_CodeSniffer is already installed, check like this:

    Ref: https://wisdmlabs.com/blog/how-to-format-php-code-to-wordpress-coding-standards-in-netbeans/
    To use it in netbeans, click: Source > Inspect…
  3. PHP Mess Detector & PDepend
    Ref: https://phpmd.org/download/index.html
    http://stackoverflow.com/questions/27958289/what-is-phpmd-and-how-to-use-it
    Installation: (Same way with php cs fixer to use composer globally)

    To find out the location for PHPMD and PDepend:



     
  4. PHP Copy/Paste Detector (PHPCPD)
    Ref: https://github.com/sebastianbergmann/phpcpd
    NOTE: DONT INSTALL FROM PEAR!
    Installation: (Use composer globally)

    To find out the location:

    Please read this: Installation of PHP Code Review Tools
    For integrating all the above tools in Netbeans!

Laravel Homestead VirtualBox Vagrant

Url: https://laravel.com/docs/5.3/homestead
       Quick Tip: Get a Homestead Vagrant VM Up and Running
       Getting Started with Laravel Homestead

Introduction
Laravel strives to make the entire PHP development experience delightful, including your local development environment. Vagrant provides a simple, elegant way to manage and provision Virtual Machines.

Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. No more worrying about messing up your operating system! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re-create the box in minutes!

Homestead runs on any Windows, Mac, or Linux system, and includes the Nginx web server, PHP 7.0, MySQL, Postgres, Redis, Memcached, Node, and all of the other goodies you need to develop amazing Laravel applications.

Installation:

  1. Install VirtualBox (https://www.virtualbox.org/wiki/Linux_Downloads)
  2. Install Vagrant (https://www.vagrantup.com/downloads.html)
  3. Installing The Homestead Vagrant Box

     
  4. Installing Homestead

    Please check ‘Homestead’ directory at Home (/home/teddy)
  5. Once you have cloned the Homestead repository, run the bash init.sh command from the Homestead directory to create the Homestead.yaml configuration file. The Homestead.yaml file will be placed in the ~/.homestead hidden directory:


     
  6. Configuring Homestead. Setting Your Provider
    The provider key in your ~/.homestead/Homestead.yaml file indicates which Vagrant provider should be used: virtualbox, vmware_fusion, or vmware_workstation. You may set this to the provider you prefer:

    Here is the file content looks like:

     
  7. Configuring Shared Folders
    I prefer to let it as is (please see ‘folders’ in ~.homestead/Homestead.yaml file above) –> DON’T DO THIS, IF ‘map’ VALUE STILL ‘~/Code’, PLEASE MODIFY IT (CHECK YOUR WEB DIRECTORY IS BETTER) BECAUSE I GOT THIS ERROR:

    MODIFY IT TO ‘~/Documents/works/laravel’ LIKE THIS:
  8. Configuring Nginx Sites
    I prefer to let it as is (please see ‘sites’ in ~.homestead/Homestead.yaml file above)
    If you change the sites property after provisioning the Homestead box, you should re-run vagrant reload –provision to update the Nginx configuration on the virtual machine.
  9. Configure SSH Key (IF NOT EXIST IN /home/teddy/.ssh/)
  10. The Hosts File
    You must add the “domains” for your Nginx sites to the hosts file on your machine. The hosts file will redirect requests for your Homestead sites into your Homestead machine. On Mac and Linux, this file is located at /etc/hosts.

    Add this line in the file:

    Make sure the IP address listed is the one set in your ~/.homestead/Homestead.yaml file. Once you have added the domain to your hosts file and launched the Vagrant box you will be able to access the site via your web browser:
  11. Launching The Vagrant Box
    Once you have edited the Homestead.yaml to your liking, run the vagrant up command from your Homestead directory. Vagrant will boot the virtual machine and automatically configure your shared folders and Nginx sites.

    BUT I GOT THIS ERROR:

    SOLUTION: (ref: Problem launching vagrant on Homestead)
    From this error

    I didn’t find ‘id_rsa’ file in /home/teddy/.ssh/ directory. I need to configure my SSH location like this:

    SEE MY MODIFICATION AT #9.
    Then I run ‘vagrant up’ again. BUT GOT ANOTHER ERROR:

    SOLUTION: (ref: Vagrant: The host path of the shared folder is missing)
    SEE MY MODIFICATION AT #7 ABOVE!
    RUN ‘vagrant up’ again! SUCCESS:

    WE CAN SEE VAGRANT INSTALLED ALSO PHP, NGINX, MYSQL, POSTGRESQL,ETC.
    Or you can see it from VirtualBox (Open Applications -> System Tools -> Oracle VM VirtualBox)vagrant-vmTHIS GUI MORE CONVENIENT. I CAN ‘START’, ‘PAUSE’ OR ‘CLOSE->POWER OFF’ THE VIRTUAL MACHINE!
    NOTE: START MUST BE FROM TERMINAL BY TYPING ‘vagrant up’. I CAN USE GUI TO START IT UP BECAUSE IT’S ALWAYS ASK FOR LOGIN AND PASSWORD THAT I DONT KNOW!
    USE ‘vagrant provision’ TO RELOAD/REFRESH VM!
    TO SHUTDOWN THE VM (NO! USE SUSPEND INSTEAD. SEE BELOW), PLEASE TYPE ‘vagrant destroy –force’
    READ (https://www.vagrantup.com/docs/cli/destroy.html): “The destroy command does not remove a box that may have been installed on your computer during vagrant up. Thus, even if you run vagrant destroy, the box installed in the system will still be present on the hard drive. To return your computer to the state as it was before vagrant up command, you need to use vagrant box remove.”
    USE SUSPEND INSTEAD OF SHUTDOWN (ref:https://scotch.io/tutorials/getting-started-with-laravel-homestead)

    SOMETIMES I FORGOT TO SUSPEND THE VM BEFORE HIBERNATING MY LAPTOP. IT’D MAKE MY LAPTOP VERY SLOW. THE TERMINAL WOULD NOT RESPOND ANYMORE FOR ANYKEY BUT I CAN OPEN THE NEW ONE OR NEW TAB. USUALLY THE VM STATUS IS PAUSED.

    I HAVE TO OPEN THE VirtualBox GUI AND DO Close -> Save State MANUALLY TO STOP THE CURRENT PROCESS!

     
  12. Use SSH to get into the VM (ref: https://www.sitepoint.com/quick-tip-get-homestead-vagrant-vm-running/)

    It seems vagrant INSTALLED ubuntu 16.04 AS VM!
    I can check the PHP version like this:

    I can browse the files and directories in it:
  13. Run http://homestead.app
    But before we do this, WE NEED TO ADD A FEW DIRECTORIES AND FILE. BECAUSE WE KNOW THE WEB ROOT FOR OUR VM IS ‘/home/vagrant/Code’ IS MAPPED TO ‘~/Documents/works/laravel’ (SEE ~/.homestead/Homestead.yaml). FOR ‘homestead.app’ (IS MAPPED TO ‘/home/vagrant/Code/Laravel/public’), ADD A NEW DIRECTORY ‘Laravel’ in /Documents/works/laravel/, THEN ADD ‘public’ DIRECTORY IN IT. THEN ADD A NEW FILE ‘index.php’ IN IT. SO THE FULL PATH IS ‘/Documents/works/laravel/Laravel/public/index.php’. In the PHP file, just add a line of code:

    THEN RUN http://homestead.app/ IN OUR BROWSER!vagrant-phpinfoI can see I’m using NGINX as a webserver instead of Apache
    vagrant-nginx
    HOW TO RUN MYSQL DATABASE???
    SOLUTION:
    REMEMBER: VAGRANT MUST BE IN ‘UP’ MODE FOR THIS SITUATION!
    Login to ssh (‘vagrant ssh’) then check the mysql location with ‘which mysql’

    From ~/.homestead/Homestead.yaml, here is the databases:

    To connect to mysql server at VM, use default user:


    So MYSQL Server version is 5.7.16
    For better for myself to connect to the mysql server, I tried to install the latest mysql client ‘MySQL Workbench’ from https://dev.mysql.com/downloads/workbench/.
    <OLD>
    Currently the version is 6.3.8. But when I installed it, I got dependenci error “Dependency is not satisfiable: libatkmm-1.6-1v5 (>=2.24.0)”. I checked again the downloaded file (mysql-workbench-community-6.3.8-1ubu1604-amd64.deb), IT’S APPARENTLY FOR UBUNTU 16.04!
    </OLD>
    <NEW>
    Ref: http://elementaryos.stackexchange.com/questions/6779/cant-install-mysql-workbench-dependency-is-not-satisfiable
    Download MySQL Workbench for Ubuntu 14.04 here http://cdn.mysql.com//archives/mysql-workbench/mysql-workbench-community-6.3.6-1ubu1404-amd64.deb THEN INSTALL. SUCCESS!
    </NEW>
    CONFIGURE MySQL Worbench TO CONNECT MySQL Server AT VM:

    vagrant-mysql-connectionvagrant-mysql-openNow I can see the database ‘homestead’. I also can create any table!

    WHERE IS NGINX CONFIGURATION FILE???
    SOLUTION:
    Use ‘vagrant ssh’ TO GET INTO THE HOME DIRECTORY OF VM. THEN GO TO THE ROOT DIRECTORY


    THE NGINX CONF FILE IN /etc/nginx/nginx.conf

    USE ‘nano’ TO OPEN/EDIT THE FILE

    Here is the file content:

    TIPS FOR USING NANO:
    TO ‘COPY’ THE TEXT AT THE TERMINAL, JUST USE MOUSE & DRAG THEN Edit->Copy
    TO ‘EXIT’  THE TERMINAL, PRESS ‘Ctrl+X’
    use CTRL-O to Save/overwrite the changes then ENTER
  14.  HOW TO CREATE NEW PROJECT ON VAGRANT???
    OK!. Make sure to run the VM (‘vagrant up’) and go to the ssh (‘vagrant ssh’). I want to clone the laravel 5 project here (Please read Install Laravel 5 On Ubuntu 14.04) For the first time, check our git and composer:

    GO TO ‘/Code’ DIRECTORY FIRST!

    NOTE: THIS IS A REMAINDER! I MADE A MISTAKE FOR THE FIRST TIME SO I HAVE TO MOVE THE LARAVEL PROJECT INTO ‘/Code’ DIRECTORY!

    OK. Create the Laravel project with name ‘laravelvagrant’

    CHECK THE NEW PROJECT ‘laravelvagrant’!

    We want to run this new project, BUT we need to modify ‘Homestead.yaml’ file first to map ‘homestead.app’ to our new project ‘laravelvagrant’. Here is the modification:

    We changed from ‘/home/vagrant/Code/Laravel/public’ to ‘/home/vagrant/Code/laravelvagrant/public’
    THEN WE NEED TO REFRESH OUR VM WITH ‘vagrant provision’! (exit from ssh first!). Then IT’S READY TO RUN homestead.app (http://homestead.app/) ON OUR BROWSER! HERE IS THE WELCOME SCREENvagrant-laravel
  15. I have a test from interviewed.com (https://upwork.interviewed.com/candidate/interviews/905600) from upwork.com about my understanding for PHP things to go into the enterprise level!. Here is the description:
    “This project assumes your computer is already set up with minimal development tools including Git, Vagrant, Composer, etc. If you don’t already have these installed, you may want to switch to the computer that you normally develop on or follow these instructions.This project uses Laravel 5.3, PHP 7.0, and SQLite (so that database is portable without seeds).Download the project and start your server:
    https://github.com/prehire/php-23093023909ad09a09
    View the project in your browser and click around: http://homestead.appMost people allocate about 1 hour to this project, but you can invest up to 4 hours if you want to. Because the project has a time limit, you can’t pause once you’ve started.”
    OK! I already setup vagrant and virtualbox
    Run the VM and go into the ssh
    Then clone the project ‘https://github.com/prehire/php-23093023909ad09a09.git’

    Go into the project ‘php-23093023909ad09a09’ then install the dependencies via composer

    Now we want to test it on our browser BUT REMEMBER TO MODIFY ‘Homestead.yaml’ FIRST!

    THEN EXIT FROM SSH & REFRESH OUR VM WITH ‘vagrant provision’!
    REFRESH OUR BROWSER (http://homestead.app/). HERE IS THE HOMEPAGE SCREEN!vagrant-project-testThe App with 4 top menu: Homework (http://homestead.app/booking OR http://homestead.app/ –> HOMEPAGE), Booking (http://homestead.app/booking), Customer (http://homestead.app/customer) and Cleaner (http://homestead.app/cleaner). Here are the screens for each of them:
    Bookingproject-test-bookingCustomerproject-test-customerCleanerproject-test-cleanerOK. THE SETUP IS OKAY. WHAT IS THE TASK FOR THIS PROJECT???
    USE PDO INSTEAD OF MYSQL!!! SETUP IT FIRST OR TRY THE AVAILABLE PROJECT IN http://myprojects.advchaweb.com/index.php/2017/01/11/cleaner-booking/ TO MAKE SURE PDO WORK IN HOMESTEAD!