TensorFlow与OpenCV,读取图片,进行简单操作并显示

1 OpenCV读入图片,使用tf.Variable初始化为tensor,加载到tensorflow对图片进行转置操作,然后opencv显示转置后的结果

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 session:
  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读入图片,使用tf.placeholder符号变量加载到tensorflow里,然后tensorflow对图片进行剪切操作,最后opencv显示转置后的结果

import tensorflow as tf
import cv2

# First, load the image again
filename = "MarshOrchid.jpg"
raw_image_data = 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)

参考资料:

http://learningtensorflow.com/

http://stackoverflow.com/questions/34097281/how-can-i-convert-a-tensor-into-a-numpy-array-in-tensorflow

TensorFlow与OpenCV,读取图片,进行简单操作并显示的更多相关文章

  1. 边缘检测︱基于 HED网络TensorFlow 和 OpenCV 实现图片边缘检测

    本文摘录自<手机端运行卷积神经网络的一次实践 – 基于 TensorFlow 和 OpenCV 实现文档检测功能> 只截取感兴趣 的片段. . 一.边缘检测 1.传统边缘检测 Google ...

  2. (第二章第二部分)TensorFlow框架之读取图片数据

    系列博客链接: (第二章第一部分)TensorFlow框架之文件读取流程:https://www.cnblogs.com/kongweisi/p/11050302.html 本文概述: 目标 说明图片 ...

  3. python opencv 读取图片 返回图片某像素点的b,g,r值

    转载:https://blog.csdn.net/weixin_41799483/article/details/80884682 #coding=utf-8   #读取图片 返回图片某像素点的b,g ...

  4. PyTorch载入图片后ToTensor解读(含PIL和OpenCV读取图片对比)

    概述 PyTorch在做一般的深度学习图像处理任务时,先使用dataset类和dataloader类读入图片,在读入的时候需要做transform变换,其中transform一般都需要ToTensor ...

  5. Opencv读取图片像素值

    #include <iostream>#include <opencv2/opencv.hpp> using namespace std;using namespace cv; ...

  6. Opencv读取图片像素值并保存为txt文件

    #include <opencv2/opencv.hpp>#include<vector>#include <fstream> using namespace st ...

  7. [OpenCV] 1、读取图片

    >_<" 安装及配置请看http://www.cnblogs.com/zjutlitao/p/4042074.html >_<" 这篇是一个简单的在VS20 ...

  8. Opencv读取各种格式图片,在TBitmap上面重绘

    //opencv读取图片 cv::Mat image; //const char *fileName = "HeadImage-UI/Photo-001.bmp"; const c ...

  9. OpenGL——OpenCV与SOIL读取图片进行纹理贴图

    使用OpenCV读取图片代码如下 img = imread(m_fileName); if (img.empty()) { fprintf(stderr, "Can not load ima ...

随机推荐

  1. Mysql中的常用函数:

    Mysql中的常用函数: 1.字符串函数: (1).合并字符串 concat():// concat('M','y',"SQL",'5.5');== MySQL5.5//当传入的参 ...

  2. ●BZOJ 3309 DZY Loves Math

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3309 题解: 莫比乌斯反演,线筛 化一化式子: f(x)表示x的质因子分解中的最大幂指数 $ ...

  3. 洛谷P3168 [CQOI2015]任务查询系统

    #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #in ...

  4. hdu 5877 线段树(2016 ACM/ICPC Asia Regional Dalian Online)

    Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  5. ●BZOJ 2005 NOI 2010 能量采集

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2005 题解: 一个带有容斥思想的递推.%%% 首先,对于一个点 (x,y) 在路径 (0,0 ...

  6. Spring学习笔记5——注解方式AOP

    第一步:注解配置业务类 使用@Component("Pservice")注解ProductService 类 package com.spring.service; import ...

  7. gray-code (格雷码)

    题目描述 The gray code(格雷码) is a binary numeral system where two successive values differ in only one bi ...

  8. html表单验证

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. java 左移 右移

    public class test{ public static void main(String[] args) { int m = 9; int n = m >> 3; int p = ...

  10. 18. 4Sum(中等)

    Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar ...