这是用于从磁盘读取图像的代码:
image_data = tf.gfile.FastGFile(imagePath, 'rb').read()
with tf.Session() as sess:
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
predictions = sess.run(softmax_tensor,
{'DecodeJpeg/contents:0': image_data})
但是现在我想使用Python和opencv从视频中捕获帧,然后使用此模型对捕获的垫子图像进行分类。 我试过了:
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
print(image_data)
imgRGB = cv2.imread(image_path)
r, buf = cv2.imencode(".jpg", imgRGB)
bytes_image = Image.fromarray(np.uint8(buf)).tobytes()
print(bytes_image)
我得到了两个相似的结果,但是不一样。
b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00
\ x00 \x00\x00\xff\xe1\x00"Exif\x00\x00MM\x00*\x00\x00\x00........
b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00C\x00\x02.......
当我叫“ sess.run”时,发现最终结果不一样。我该如何解决?