使用下面的代码,我使用OpenCV和Tensorflow读取相同的图像.
import tensorflow as tf
import cv2
def get_image(image_path):
    """Reads the jpg image from image_path.
    Returns the image as a tf.float32 tensor
    Args:
        image_path: tf.string tensor
    Reuturn:
        the decoded jpeg image casted to float32
    """
    return tf.image.convert_image_dtype(
        tf.image.decode_jpeg(
            tf.read_file(image_path), channels=3),
        dtype=tf.uint8)
path = "./images/2010_006748.jpg"
original_image = cv2.imread(path)
image_tensor = get_image(tf.constant(path))
# convert to uint8
image_tensor = tf.image.convert_image_dtype(image_tensor, dtype=tf.uint8)
with tf.Session() as sess:
    image = sess.run(image_tensor)
cv2.imshow("tf", image)
cv2.imshow("original", original_image)
cv2.waitKey(0)
正如你可以从图片看,疗法是通过OpenCV的(正确的颜色)和Tensorflow(错误的颜色)读取图像之间的差异.
我尝试使用Tensorflow图像的颜色进行标准化,cv2.normalize(image, image, 0, 255, cv2.NORM_MINMAX, dtype=cv2.CV_8UC3)但没有任何改变.
我还尝试将图像读取为tf.uint8(删除初始转换为tf.float32)但没有更改.
如何正确使用OpenCV显示使用Tensorflow读取的图像?
尝试:
bgr_img = cv2.cvtColor(original_image, cv2.COLOR_RGB2BGR)
| 归档时间: | 
 | 
| 查看次数: | 2671 次 | 
| 最近记录: |