python将信息加密进图片
从图片中解密信息
>>> runfile(r'K: estpro est1.py', wdir=r'K: estpro')
http://blog.csdn.net/myhaspl
myhaspl@qq.com
loading ...
正在处理中 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
>>>
往图片加密信息
>>> runfile(r'K: estpro est.py', wdir=r'K: estpro')
http://blog.csdn.net/myhaspl
myhaspl@qq.com
loading ...
正在处理中 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
>>>
加密python代码
#!/usr/bin/env python #-*- coding: utf-8 -*- #code:myhaspl@qq.com #http://blog.csdn.net/myhaspl import cv2 import numpy as np fn1="he1.jpg" fn2="he2.jpg" fn3="secret.png" redcolor=(0, 0, 255) if __name__ == '__main__': print 'http://blog.csdn.net/myhaspl' print 'myhaspl@qq.com' print print 'loading ...' print u'正在处理中', img1 = cv2.imread(fn1) img2 = cv2.imread(fn2) w=img1.shape[1] h=img1.shape[0] #加上需要隐藏的消息 cv2.putText(img1,"http://blog.csdn.net/myhaspl", (20,20),cv2.FONT_HERSHEY_PLAIN, 1.0, redcolor, thickness = 1) cv2.putText(img1,"code by myhaspl:myhaspl@qq.com", (20,60),cv2.FONT_HERSHEY_PLAIN, 1.0, redcolor, thickness = 1) cv2.putText(img1,"Installing Python is generally easy. ", (1,90),cv2.FONT_HERSHEY_PLAIN, 1, redcolor, thickness = 1) cv2.namedWindow('img1') cv2.imshow('img1', img1) cv2.namedWindow('img2-1') cv2.imshow('img2-1', img2) #处理隐藏目标图 #将所有蓝色值变成奇数 for j in xrange(0,h): for i in xrange(0,w): if (img2[j,i,0]%2)==1: img2[j,i,0]=img2[j,i,0]-1 print '.', mirror_w=w/2 #读取源图,并将信息写入目标图 for j in xrange(0,h): for i in xrange(0,w): if (img1[j,i,0],img1[j,i,1],img1[j,i,2])==redcolor: img2[j,i,0]=img2[j,i,0]+1 print '.', #保存修改后的目标图,并显示 cv2.namedWindow('img2-2') cv2.imshow('img2-2', img2) cv2.imwrite(fn3, img2) cv2.waitKey() cv2.destroyAllWindows()
本博客所有内容是原创,未经书面许可,严禁任何形式的转载
http://blog.csdn.net/u010255642
加密过程的效果图
解密的python代码
#!/usr/bin/env python #-*- coding: utf-8 -*- #code:myhaspl@qq.com #http://blog.csdn.net/myhaspl #解码文件 import cv2 import numpy as np fn="secret.png" if __name__ == '__main__': print 'http://blog.csdn.net/myhaspl' print 'myhaspl@qq.com' print print 'loading ...' print u'正在处理中', img = cv2.imread(fn) w=img.shape[1] h=img.shape[0] imginfo =np.zeros((h,w,3), np.uint8) for j in xrange(0,h): for i in xrange(0,w): if (img[j,i,0]%2)==1: imginfo[j,i,1]=255 print '.', cv2.imshow('info', imginfo) cv2.imwrite(fn, imginfo) cv2.waitKey() cv2.destroyAllWindows()
解密后的效果图