PHP code example of mohuishou / image-ocr
1. Go to this page and download the library: Download mohuishou/image-ocr library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mohuishou / image-ocr example snippets
$image=new Image($img_path);
$image_ocr=new ImageOCR($image)
$image_ocr->setMaxGrey(90);
$image_ocr->setMinGrey(10);
$image_ocr->setStandardWidth(13);
$image_ocr->setStandardHeight(20);
$image_ocr->setDebug(true);
try{
$image_ocr->grey();
}catch (\Exception $e){
echo $e->getMessage();
}
try{
$image_ocr->hash($max_grey=null,$min_grey=null);
}catch (\Exception $e){
echo $e->getMessage();
}
try{
$image_ocr->removeSpots();
}catch (\Exception $e){
echo $e->getMessage();
}
try{
//使用之前需要初始化连通域对象
$image_ocr->setImageConnect();
//除噪
$image_ocr->removeSpotsByConnect();
}catch (\Exception $e){
echo $e->getMessage();
}
try{
//使用之前需要初始化连通域对象
$image_ocr->setImageConnect();
//分割
$image_ocr->splitByConnect();
}catch (\Exception $e){
echo $e->getMessage();
}
try{
$standard_data=$image_ocr->standard();
}catch (\Exception $e){
echo $e->getMessage();
}
ImageOCR::__construct(Image $image)
ImageOCR::saveImage($path)
ImageOCR::grey()
ImageOCR::hash($max_grey=null,$min_grey=null)
ImageOCR::hashByBackground($model=self::MAX_MODEL,$max_grey=null,$min_grey=null)
ImageOCR::removeSpots()
ImageOCR::removeSpotsByConnect()
ImageOCR::standard()
ImageOCR::setImageConnect()
ImageOCR::setImage(Image $image)
ImageOCR::getStandardData()
ImageOCR::setMaxGrey($max_grey)
ImageOCR::setMinGrey($min_grey)
ImageOCR::setStandardWidth($standard_width)
ImageOCR::setStandardHeight($standard_height)
//ImageTool的方法均为静态方法
ImageTool::removeZero($data)
ImageTool::removeZeroColumn($hash_data)
ImageTool::drawBrowser($data)
ImageTool::transposeAndRemoveZero($hash_data)
ImageTool::hashTranspose($hash_data)
ImageTool::img2hash($img)
ImageTool::hash2img($hash_data,$padding=0)