zoukankan      html  css  js  c++  java
  • python手记(31)

    #!/usr/bin/env python
    #-*- coding: utf-8 -*-
    import cv2
    import numpy as np
    
    
    fn="test2.jpg"
    
    if __name__ == '__main__':
        print 'http://blog.csdn.net/myhaspl'
        print 'myhaspl@qq.com'
        print
        print 'loading %s ...' % fn
        print '正在处理中',
        img = cv2.imread(fn)
        w=img.shape[1]
        h=img.shape[0]    
        ii=0
        #生成日落效果
        #b[:,:] = img[:,:,0]  
        #g[:,:] = img[:,:,1]  
        #r[:,:] = img[:,:,2]  
        for xi in xrange(0,w):
            for xj in xrange (0,h):
                img[xj,xi,0]= int(img[xj,xi,0]*0.7)
                img[xj,xi,1]= int(img[xj,xi,1]*0.7)
            if  xi%10==0 :print '.',          
        cv2.namedWindow('img')     
        cv2.imshow('img', img) 
        cv2.waitKey()
        cv2.destroyAllWindows()
    

    以下是数组存放红、绿、蓝的位置

        #b[:,:] = img[:,:,0]  
        #g[:,:] = img[:,:,1]  
        #r[:,:] = img[:,:,2]

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


    loading test2.jpg ...
    正在处理中 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    >>> 




    原图是:




    也可以如下操作

    #!/usr/bin/env python
    #-*- coding: utf-8 -*-
    import cv2
    import numpy as np
    
    
    fn="test2.jpg"
    
    if __name__ == '__main__':
        print 'http://blog.csdn.net/myhaspl'
        print 'myhaspl@qq.com'
        print
        print 'loading %s ...' % fn
        print '正在处理中',
        img = cv2.imread(fn)
        w=img.shape[1]
        h=img.shape[0]    
        ii=0
        #生成日落效果
        #取色彩分量
        b, g, r = cv2.split(img)
        b=b*0.7
        g=g*0.7
        #直接通过索引改变色彩分量 
        img[:,:,0]=b
        img[:,:,1]=g        
        cv2.namedWindow('img')     
        cv2.imshow('img', img) 
        cv2.waitKey()
        cv2.destroyAllWindows()
    



  • 相关阅读:
    js如何识别后端返回的“↵”,让其换行
    ReactNative插件
    ReactNative踩坑
    js对当前时间进行处理
    vue-awesome-swiper手动滑动后不再自动轮播的问题
    HTML5知识点汇总
    懒加载的实现原理及一些实现方法
    使用node.js实现多人聊天室(socket.io、B/S)
    [vue学习] 卡片展示分行功能简单实现
    [vue学习]快速搭建一个项目
  • 原文地址:https://www.cnblogs.com/james1207/p/3271078.html
Copyright © 2011-2022 走看看