cpp真难,卧槽。还有没找到一本好的gpu for cpp的书。最后决定用tensorflow来实现算法吧,下面是一些基础的,给出了有加速和无加速两个版本。以后都用有加速的,算法opencv中慢慢实现,会更新到我的github上。
import tensorflow as tf
from matplotlib import pyplot as plt
# 第一个版本 有加速版
lena = tf.gfile.GFile(r"E:\py_code\img_treatment\img\forest.png",'rb').read()
image = tf.image.decode_jpeg(lena)
image_data = image
resized = tf.image.resize_images(image_data,[30,30],method=1)
crop = tf.image.resize_image_with_crop_or_pad(image_data,200,200)
crop_coff = tf.image.central_crop(image_data,0.5)
with tf.Session() as sess:
r1=sess.run(resized)
n = 3
plt.subplot(1,n,1)
plt.imshow(r1)
c1 = sess.run(crop)
plt.subplot(1,n,2)
plt.imshow(c1)
c2=sess.run(crop_coff)
plt.subplot(1,n,3)
plt.imshow(c2)
plt.show()
# 第二个版本 无加速版
lena = tf.gfile.GFile(r"E:\py_code\img_treatment\img\forest.png",'rb').read()
with tf.Session() as sess:
image = tf.image.decode_jpeg(lena)
image_data = image.eval()
resized = tf.image.resize_images(image_data,[30,30],method=1)
crop = tf.image.resize_image_with_crop_or_pad(image_data,200,200)
crop_coff = tf.image.central_crop(image_data,0.5)
n = 3
plt.subplot(1,n,1)
plt.imshow(resized.eval())
plt.subplot(1,n,2)
plt.imshow(crop.eval())
plt.subplot(1,n,3)
plt.imshow(crop_coff.eval())
plt.show()
有加速的和无加速的相差了6倍多左右,我用的是ubuntu+GPU 1070+CPU i7_8+16G测得