• python手记(52)


    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()         

    解密后的效果图



  • 相关阅读:
    从零开始学android -- dialog
    Java学习笔记之equals和Objects.equals
    windows svchost.exe 引起的出现的莫名其妙的窗口失去焦点
    android.util.AndroidRuntimeException Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? com.uethinking.microvideo.manag
    从零开始搭建android框架系列(转)
    js-ES6学习笔记-编程风格(1)
    js-ES6学习笔记-module(4)
    js-ES6学习笔记-module(3)
    js-ES6学习笔记-module(2)
    js-ES6学习笔记-module(1)
  • 原文地址:https://www.cnblogs.com/riskyer/p/3289831.html
Copyright © 2020-2023  润新知