TensorFlow and OpenCV, read pictures, perform simple operations and display
1 OpenCV read into the picture, using TF. Variable initialized to tensor, loaded into TensorFlow to transpose the picture, then OpenCV shows the result of the transpose
Import TensorFlow as tf
import cv2
file_path = "/home/lei/desktop/"
filename = "marshorchid.jpg"
image = Cv2.imread (filename, 1)
Cv2.namedwindow (' image ', 0)
cv2.imshow (' image ', image)
# Create a TensorFlow Variable
x = tf. Variable (image, Name= ' x ')
model = Tf.initialize_all_variables () with
TF. Session () as sessions:
x = Tf.transpose (x, perm=[1, 0, 2])
Session.run (model) Result
= Session.run (x)
Cv2.namedwindow (' result ', 0)
cv2.imshow ("result", result)
Cv2.waitkey (0)
2 OpenCV read into the picture, use the Tf.placeholder symbol variable to load into the TensorFlow, then tensorflow the picture to cut operations, and finally OPENCV show the result of the transpose
Import TensorFlow as tf
import cv2
# I, load the image again
filename = "marshorchid.jpg"
raw_image_d ATA = cv2.imread (filename)
image = Tf.placeholder ("Uint8", [None, none, 3])
slice = tf.slice (image, [1000, 0, 0], [3000,-1,-1])
With TF. Session () as session: Result
= Session.run (slice, feed_dict={image:raw_image_data})
print (Result.shape)
Cv2.namedwindow (' image ', 0)
cv2.imshow (' image ', result)
Cv2.waitkey (0)
Resources:
http://learningtensorflow.com/
Http://stackoverflow.com/questions/34097281/how-can-i-convert-a-tensor-into-a-numpy-array-in-tensorflow