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. APK扩展文件介绍、功能及用法

    APK扩展文件介绍 Android Market (Google Play Store)中每一个APK文件的最大限制是50MB.假设您的程序中包括大量的数据文件,曾经您仅仅能把这些数据文件放到自己的s ...

  2. 设计模式之Prototype(c++)

    Prototype模型: 作用: 用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象----克隆(clone)对象. Prototype模型类图如下: 形象说明:如果客户想配钥匙(Conc ...

  3. Windows 8 动手实验系列教程 实验5:进程生命周期管理

    动手实验 实验5:进程生命周期管理 2012年9月 简介 进程生命周期管理对构建Windows应用商店应用的开发者来说是需要理解的最重要的概念之一.不同于传统的Windows应用(它们即使在后台仍然继 ...

  4. 自己写一个jqery的拖拽插件

    说实话,jQuery比原生的js好用多了,本来想用原生写的,也写出来的,仅仅是,感觉不像插件,所以用jQuery实现了一版. 实现的功能:能够指定拖拽的边界,在拖拽过程中,能够触发几个自己定义事件 先 ...

  5. Redis util

    主要是字符串通配符匹配和数字与字符串互转的几个函数. // 通配符模式匹配 int stringmatchlen(const char* p, int plen, const char* s, int ...

  6. 《c陷阱与缺陷》笔记--注意边界值

    如果要自己实现一个获取绝对值的函数,应该都没有问题,我这边也自己写了一个: void myabs(int i){ if(i>=0){ printf("%d\n",i); }e ...

  7. c++(重载、覆盖、隐藏)

    源地址:http://www.cnblogs.com/qlee/archive/2011/07/04/2097055.html 成员函数的重载.覆盖与隐藏成员函数的重载.覆盖(override)与隐藏 ...

  8. Android 编程之第三方开发 MaoZhuaWeiBo微博开发演示样例-1

    在大学期间我做过非常多类似这种APP.这个是我们小组之前做的,我后期增加非常多新元素.完好了这个应用,由于为了加强 专业技术嘛.也是常常熬夜写些小东西,嘿嘿.只是还算不错.起码技术长进了不少嘛,还是非 ...

  9. JAVA中enum的常见用法

    JAVA中enum的常见用法包括:定义并添加方法.switch.遍历.EnumSet.EnumMap 1.定义enum并添加或覆盖方法 public Interface Behaviour{ void ...

  10. OCA读书笔记(11) - 实现Oracle数据库审计

    11 Implementing Oracle Database Auditing 描述DBA对于安全和审计的职责使能标准的数据库审计安全审计选项查看审计信息维护审计路径 最小权限原则只在计算机上安装所 ...