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. XDU 1284 寻找礼物

    枚举+二分查找. A+B+C >= K  ---->   C >= K - A -B    ----> 统计大于等于C的个数就可以. #include <cstdio&g ...

  2. 内省(一)之Introspector、BeanInfo、PropertyDescriptor

    内省(Introspector)是专门用来操作JavaBean属性的.不是所有的字段(Field)都能被称之为属性,只有某些字段具有getXXX或setXXX方法的才能称之为属性,当然要称为是一个Be ...

  3. Java描述语言、国家和地理的类——Locale

    Locale类代表一个特定的地理.语言和国家环境.一个Locale的实例对象本身不会验证它代表的语言和国家地区信息是否正确,只是向一些对国家和语言.地理等比较敏感的类提供国家地区语言信息,这些类有Da ...

  4. SpringMVC从Control中响应json数据

    在页面上异步获取Controller中响应的json数据. <%@ page language="java" contentType="text/html; cha ...

  5. Eclipse无提示的解决办法 和 内容辅助技巧

    Eclipse无提示的解决办法 和 内容辅助技巧 一.若发现内容辅助失效没有提示 下面是解决办法,现贴出来与大家共享:       1.菜单window->Preferences->Jav ...

  6. 使用python进行加密解密AES算法

    使用python进行加密解密AES算法-代码分享-PYTHON开发者社区-pythoner.org 使用python进行加密解密AES算法 TY 发布于 2011-09-26 21:36:53,分类: ...

  7. 一次ORA-03113错误解决

    ---------------------------------------------------------------------------- -----------------ORA错误处 ...

  8. How to append files to a .tar archive using Apache Commons Compress?(转)

    I created a copy of the tar archive and copied to entire content to it. Then I delete the old tar ar ...

  9. SilkTest Q&A 3

    Q21:如何给testcase的属性赋值? A21: 1.确定你的testplan处于打开状态. 2.点击你准备赋属性值的testcase 3.点击TestPlan/detail菜单,testplan ...

  10. linux ifconfig命令使用详解

    Linux下网卡命名规律:eth0,eth1.第一块以太网卡,第二块.lo为环回接口,它的IP地址固定为127.0.0.1,掩码8位.它代表你的机器本身. 1.ifconfig是查看网卡的信息. if ...