我在使用json时遇到麻烦。 我正在尝试将通过json接收的图像转换为2D numpy数组。 我已经尝试了一些方法,但是没有任何效果。
这是我获取图像的方式:
@app.route("/<path:fullurl>", methods=['GET', 'POST'])
def main(fullurl):
height, width = [int(e) for e in fullurl.split('/')]
jsonResponse = json.loads(request.data.decode('utf-8'))
我还尝试打印jsonResponse ['image'],这是我得到的:
"data:image/octet-stream;base64,iVBORw0KGgoAAAANSUhEUgAAAeAAAAHgCAYAAAB91L6VAAAF9klEQVR4nO3dv4qU
VxjH8d8l5Ea8jb2CdBbZxlbsvITUAdPkKmxjIQGrpLAIhA1EJaCQTSIiS1jXP7tJMUrmPe5ugjrPM5
z5fOB0y/K81Zdz3jMzCQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQ7zTJ2YbXaZI3SQ6LngkAttpZ
kr+b17tIn2z4WQFga2xDgC+KMgBM69usjoe7gyvEAFDgMKvw/9
/4CzEAbNBJLj8WF2IA2LCLQizCAFDgvBADAEXsggGgwbgTBgAK/JRlgL
/uHQcAdodjaABo4DIWADQQYABoIMAA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AAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAPgHU+BofAK5zHIAAAAASUVORK5CYII="
非常感谢您的帮助= D
答案 0 :(得分:0)
好吧,我想出了解决我问题的方法。很简单,我从json对象收到的代表我的图像的字符串是用base64编码的,这是事实。由于当时我对json对象或base64一无所知,所以我没有意识到在字符串的开头有一个标头。因此,我的解决方案如下:
DossierModule
我只是用逗号分割字符串:在它之前是标题,在它之后是图像。然后我将其写入png文件中,并使用cv2将其打开以具有正确的numpy数组。
bitewise_not 功能仅适用于我的特定应用程序,不是必需的。
我希望这对以后的某个人会有所帮助! = D