You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reformat_input function in file easyocr/utils.py is inconsistent in the way it computes greyscale image-array img_cv_grey, and the format (RGB or BGR) of the 3-channel img image-array, depending on the type of the input image to reformat_input
If image is a Path-like object or URL, the img will be an RGB image-array and img_cv_grey will be computed using cv2.imread(image, cv2.IMREAD_GRAYSCALE). So, these two are consistent. And furthermore, looking at the way the detector CRAFT is used, I assume that the image-array is supposed to be an RGB-ordered array.
If image is of type bytes. Then the code reads
nparr = np.frombuffer(image, np.uint8)
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_cv_grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
Here imgwill be an image-array ordered as RGB exactly as above. But the last line is clearly wrong, and should read
img_cv_grey = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
since img has been transforms to an RGB ordered image-array in the line above.
If image is an numpy array, then img is ordered as BGR, which is different to the cases above.
For PIL-JPEG image, img is again an BGR ordered image-array
If it is as I assume, that detector expects an RGB ordered image-array, I think that the cases of image being a numpy array of PIL-JPEG are both wrong. In any case, it is non-consistent to the cases of image being Path/URL-like or a byte-array.
Furthermore in case 1, the img_cv_grey is computed using the cv2.imread functionality, which produces a slightly different output than cv2.cvtColor(img, cv2.COLOR_RGB2GRAY). Also, since the image is read once more in the function loadImage in file easyocr/imgproc.py using the skimage.io.imread, I think it is unnecessary to read the image path twice. Better to load the image and then convert to img_cv_grey using cvtColor. I assume that that is cheaper computationally.
The text was updated successfully, but these errors were encountered:
The
reformat_input
function in file easyocr/utils.py is inconsistent in the way it computes greyscale image-arrayimg_cv_grey
, and the format (RGB or BGR) of the 3-channelimg
image-array, depending on the type of the inputimage
toreformat_input
If
image
is a Path-like object or URL, theimg
will be an RGB image-array andimg_cv_grey
will be computed usingcv2.imread(image, cv2.IMREAD_GRAYSCALE)
. So, these two are consistent. And furthermore, looking at the way the detector CRAFT is used, I assume that the image-array is supposed to be an RGB-ordered array.If
image
is of type bytes. Then the code readsnparr = np.frombuffer(image, np.uint8)
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_cv_grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
Here
img
will be an image-array ordered as RGB exactly as above. But the last line is clearly wrong, and should readimg_cv_grey = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
since img has been transforms to an RGB ordered image-array in the line above.
If
image
is an numpy array, thenimg
is ordered as BGR, which is different to the cases above.For PIL-JPEG image,
img
is again an BGR ordered image-arrayIf it is as I assume, that detector expects an RGB ordered image-array, I think that the cases of image being a numpy array of PIL-JPEG are both wrong. In any case, it is non-consistent to the cases of
image
being Path/URL-like or a byte-array.Furthermore in case 1, the img_cv_grey is computed using the
cv2.imread
functionality, which produces a slightly different output thancv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
. Also, since the image is read once more in the functionloadImage
in fileeasyocr/imgproc.py
using theskimage.io.imread
, I think it is unnecessary to read the image path twice. Better to load the image and then convert to img_cv_grey using cvtColor. I assume that that is cheaper computationally.The text was updated successfully, but these errors were encountered: