I use python to read an image from url and save it, by using opencv imdecode: read url demo
import numpy as np
import urllib
import cv2
def url_to_image(url):
resp = urllib.urlopen(url)
data = bytearray(resp.read())
image = np.asarray(data, dtype="uint8")
image = cv2.imdecode(image, cv2.IMREAD_COLOR)
return image
In my understanding: decoding is turing some encoded data into un-encoded data, for example, when you read .jpg, you need to decode the Jpeg2000 code into readable data. When you decode a 64base code, you need to do the 64base code into regular number. In a word, I think decoding need to change the data or data length.
In this code, I think "resp.read()" already read and decoded the raw bits flow (01001010...) to uint8 numbers(7,8,123,255...) And what "imdecode" did is only turning the long pix array into opencv format, it is only the re-ordering pixel instead of decoding. In this process, 255 is also 255, the data length and data itself didn't change.
As the demo says:"To reshape the array into a 2D format, assuming 3 components per pixel (i.e. the Red, Green, and Blue components, respectively), we make a call to cv2.imdecode "
If so, why imdecode called decode since it didn't do any decoding work?