python手记(52)
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 '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 '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)的更多相关文章
- Python 3.52官方文档翻译 http://usyiyi.cn/translate/python_352/library/index.html 必看!
Python 3.52官方文档翻译 http://usyiyi.cn/translate/python_352/library/index.html 觉得好的麻烦点下推荐!谢谢!
- python手记(50)
#!/usr/bin/env python # -*- coding: utf-8 -*- #http://blog.csdn.net/myhaspl #code:myhaspl@qq.com imp ...
- python手记(26)
#!/usr/bin/env python import cv2 import sys fn="test2.jpg" if __name__ == '__main__': prin ...
- python手记(32)
#!/usr/bin/env python #-*- coding: utf-8 -*- import cv2 import numpy as np fn="test2.jpg" ...
- python手记(30)
#!/usr/bin/env python #-*- coding: utf-8 -*- import cv2 import numpy as np fn="test3.png" ...
- python手记(31)
#!/usr/bin/env python #-*- coding: utf-8 -*- import cv2 import numpy as np fn="test2.jpg" ...
- python手记(38)
runfile(r'K:\testpro\testopencv.py', wdir=r'K:\testpro') http://blog.csdn.net/myhaspl myhaspl@qq.com ...
- python手记(39)
#!/usr/bin/env python #-*- coding: utf-8 -*- #code:myhaspl@qq.com import cv2 import numpy as np fn=& ...
- python手记(45)
python 声音编辑,减少音量 #!/usr/bin/env python # -*- coding: utf-8 -*- #http://blog.csdn.net/myhaspl #code:m ...
随机推荐
- 使用JDBC进行数据库的事务操作(1)
本篇讲述数据库中非常重要的事务概念和如何使用MySQL命令行窗口来进行数据库的事务操作.下一篇会讲述如何使用JDBC进行数据库的事务操作. 事务是指数据库中的一组逻辑操作,这个操作的特点就是在该组逻辑 ...
- 【ASP.NET Web API教程】2.3.3 创建Admin控制器
原文:[ASP.NET Web API教程]2.3.3 创建Admin控制器 注:本文是[ASP.NET Web API系列教程]的一部分,如果您是第一次看本博客文章,请先看前面的内容. Part 3 ...
- C中的几组指针
1.二维数组 下面就三种二维数组进行说明. 1: int **Ptr; 2: int *Ptr[ 5 ]; 3: int ( *Ptr )[ 5 ]; 以上三例都是整数的二维数组,都可以用形如 Ptr ...
- golang做的邮件服务器
https://gowalker.org/github.com/gleez/smtpd https://www.v2ex.com/t/133221
- hdu1427之速算24点
速算24点 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- 将markdown格式转化为bootstrap风格html
前言:这些年markdown格式的文件很流行,像github里project说明文档都是用markdown格式编写. 一方面,我们能够通过pandoc将markdown文件转换为html,这样将htm ...
- OMR数据查询
查询 1.查询所有的. var query = from p in _Context.Info select p; var query = _Context.Info; 2.单条件查询 等值查 var ...
- QS Network(最小生成树)
题意:若两个QS之间要想连网,除了它们间网线的费用外,两者都要买适配器, 求使所有的QS都能连网的最小费用. 分析:这个除了边的权值外,顶点也有权值,因此要想求最小价值,必须算边及顶点的权值和. 解决 ...
- mysql update 有无索引对比
<pre name="code" class="html">mysql> desc ProductInfo; +--------------- ...
- Hbase0.96源码之HMaster(一)
从main()函数開始 public static void main(String [] args) { VersionInfo.logVersion(); new HMasterCommandLi ...