forked from gitanat/simple-ocr-opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
11 changed files
with
177 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from .files import Image | ||
from PIL import Image | ||
import numpy | ||
import cv2 | ||
|
||
|
||
def image_to_pil(imagefile): | ||
"""Convert an ImageFile or ImageBuffer object to a Pillow Image object | ||
:param imagefile: ImageFile object | ||
:return: Image object | ||
""" | ||
pillow = cv2.cvtColor(imagefile.image, cv2.COLOR_BGR2RGB) | ||
return Image.fromarray(pillow) | ||
|
||
|
||
def pil_to_image(pillow): | ||
"""Convert a Pillow Image object to an ImageBuffer object""" | ||
return Image.fromarray(pil_to_cv_array(pillow)) | ||
|
||
|
||
def pil_to_cv_array(pillow): | ||
"""Convert a Pillow Image object to a cv compatible array""" | ||
imagefile = numpy.array(pillow) | ||
return imagefile[:, :, ::-1].copy() |
Oops, something went wrong.