python将信息加密进图片

从图片中解密信息

>>> runfile(r'K:\testpro\test1.py', wdir=r'K:\testpro')

http://blog.csdn.net/myhaspl
myhaspl@qq.com

loading  ...

正在处理中 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

>>>

往图片加密信息

>>> runfile(r'K:\testpro\test.py', wdir=r'K:\testpro')
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()

解密后的效果图

python手记(52)的更多相关文章

  1. Python 3.52官方文档翻译 http://usyiyi.cn/translate/python_352/library/index.html 必看!

    Python 3.52官方文档翻译   http://usyiyi.cn/translate/python_352/library/index.html 觉得好的麻烦点下推荐!谢谢!

  2. python手记(50)

    #!/usr/bin/env python # -*- coding: utf-8 -*- #http://blog.csdn.net/myhaspl #code:myhaspl@qq.com imp ...

  3. python手记(26)

    #!/usr/bin/env python import cv2 import sys fn="test2.jpg" if __name__ == '__main__': prin ...

  4. python手记(32)

    #!/usr/bin/env python #-*- coding: utf-8 -*- import cv2 import numpy as np fn="test2.jpg" ...

  5. python手记(30)

    #!/usr/bin/env python #-*- coding: utf-8 -*- import cv2 import numpy as np fn="test3.png" ...

  6. python手记(31)

    #!/usr/bin/env python #-*- coding: utf-8 -*- import cv2 import numpy as np fn="test2.jpg" ...

  7. python手记(38)

    runfile(r'K:\testpro\testopencv.py', wdir=r'K:\testpro') http://blog.csdn.net/myhaspl myhaspl@qq.com ...

  8. python手记(39)

    #!/usr/bin/env python #-*- coding: utf-8 -*- #code:myhaspl@qq.com import cv2 import numpy as np fn=& ...

  9. python手记(45)

    python 声音编辑,减少音量 #!/usr/bin/env python # -*- coding: utf-8 -*- #http://blog.csdn.net/myhaspl #code:m ...

随机推荐

  1. 第13章、布局Layouts之RelativeLayout相对布局(从零開始学Android)

    RelativeLayout相对布局 RelativeLayout是一种相对布局,控件的位置是依照相对位置来计算的,后一个控件在什么位置依赖于前一个控件的基本位置,是布局最经常使用,也是最灵活的一种布 ...

  2. JS - 焦点图

    下载地址:http://www.lanrentuku.com/js/jiaodiantu-1076.html 修改焦点图: CSS代码: /* 懒人图库 搜集整理 www.lanrentuku.com ...

  3. Servlet的学习(三)

    本篇接上一篇<Servlet的学习(二)> ,主要讲诉如何使用MyEclipse来开发Servlet,和导入Servlet所需要的源代码. 现在我们来创建一个web应用,就叫[myserv ...

  4. 在springmvc中配置jedis(转)

    主要学习https://github.com/thinkgem/jeesite.一下代码均参考于此并稍作修改. 1.jedis 首先,需要添加jedis: <!--jedis--> < ...

  5. 【Cocos2d-X游戏实战开发】捕鱼达人之单例对象的设计(二)

    本系列学习教程使用的是cocos2d-x-2.1.4(最新版为cocos2d-x-2.1.5)    博主发现前两个系列的学习教程被严重抄袭,在这里呼吁大家请尊重开发者的劳动成果, 转载的时候请务必注 ...

  6. windows下eclipse跑junit报错:CreateProcess error=206

    from:http://isuifengfei.iteye.com/blog/1684262 windows下,eclipse中运行junit出现错误提示: Exception occurred ex ...

  7. 让自己的软件实现拖拽打开文件(使用WM_DROPFILES消息和DragQueryFile函数)

    //声明 protected procedure WMDROPFILES(var Msg : TMessage); message WM_DROPFILES; //实现 procedure TForm ...

  8. java之jvm学习笔记三(Class文件检验器)

    java之jvm学习笔记三(Class文件检验器) 前面的学习我们知道了class文件被类装载器所装载,但是在装载class文件之前或之后,class文件实际上还需要被校验,这就是今天的学习主题,cl ...

  9. 成都Java培训机构太多,该如何选择呢?

    Java培训的势头愈发火热.越来越多的人看到了Java培训的前途所在,可是最好的Java培训机构是哪家呢?如何推断一家Java培训机构的专业性呢?140610lscs" target=&qu ...

  10. Android开发技术周报

    Android开发技术周报 原文  http://androidweekly.cn/android-dev-weekly-issue48/ 教程 深入理解Android之Gradle Gradle是当 ...