TensorFlow and OpenCV, read pictures, perform simple operations and display _tensorflow

Source: Internet
Author: User

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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.