I want to convert image (.jpg) to binary array. Because I have to use this array to my scrambler operating on it saved in file. Which library and and functions should I use?
-
Check out this link: stackoverflow.com/questions/13550376/…Colin Burke– Colin Burke2018-04-16 23:39:43 +00:00Commented Apr 16, 2018 at 23:39
-
1Possible duplicate of PIL image to array (numpy array to array) - Pythoncoagmano– coagmano2018-04-16 23:44:51 +00:00Commented Apr 16, 2018 at 23:44
-
OP mentioned in a comment that he's using Python 3.6.4, so PIL won't actually help him, and I'm guessing that he'll need a Python 3 alternative.Daniel Li– Daniel Li2018-04-17 00:14:50 +00:00Commented Apr 17, 2018 at 0:14
-
@ZeBirdeh Hopefully he's going to incorporate that information into the post because, as it stands, the question needs work.chb– chb2018-04-17 00:49:41 +00:00Commented Apr 17, 2018 at 0:49
Add a comment
|
3 Answers
You should take a look at the openCV library.
import cv2
img = cv2.imread('image.jpg', flags=cv2.IMREAD_COLOR)
2 Comments
Kamil_K
ModuleNotFoundError: No module named 'cv2' || I can't use cv2, there is no option to import it. I have Python3.6.4
Kim Clarence Penaflor
You should install the opencv module first for this to work. pypi.org/project/opencv-python
You can use the python library: PIL & numpy. Click here to learn more about image handling in python.
import numpy
import PIL
img = PIL.Image.open("foo.jpg").convert("L")
imgarr = numpy.array(img)