• 吴裕雄 python深度学习与实践(8)


    import cv2
    import numpy as np
    
    img = cv2.imread("G:\MyLearning\TensorFlow_deep_learn\data\lena.jpg")
    img_hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
    turn_green_hsv = img_hsv.copy()
    turn_green_hsv[:,:,0] = (turn_green_hsv[:,:,0] - 30 ) % 180
    turn_green_img = cv2.cvtColor(turn_green_hsv,cv2.COLOR_HSV2BGR)
    cv2.imshow("test",turn_green_img)
    cv2.waitKey(0)

    import cv2
    
    img = cv2.imread("G:\MyLearning\TensorFlow_deep_learn\data\lena.jpg")
    img_hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
    less_color_hsv = img_hsv.copy()
    less_color_hsv[:, :, 1] = less_color_hsv[:, :, 1] * 0.6
    turn_green_img = cv2.cvtColor(less_color_hsv, cv2.COLOR_HSV2BGR)
    cv2.imshow("test",turn_green_img)
    cv2.waitKey(0)

    import cv2
    
    img = cv2.imread("G:\MyLearning\TensorFlow_deep_learn\data\lena.jpg")
    img_hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
    less_color_hsv = img_hsv.copy()
    less_color_hsv[:, :, 2] = less_color_hsv[:, :, 2] * 0.6
    turn_green_img = cv2.cvtColor(less_color_hsv, cv2.COLOR_HSV2BGR)
    cv2.imshow("test",turn_green_img)
    cv2.waitKey(0)

    import cv2
    import numpy as np
    import matplotlib.pyplot as plt
    
    img = plt.imread("G:\MyLearning\TensorFlow_deep_learn\data\lena.jpg")
    gamma_change = [np.power(x/255,0.4) * 255 for x in range(256)]
    gamma_img =  np.round(np.array(gamma_change)).astype(np.uint8)
    img_corrected = cv2.LUT(img, gamma_img)
    plt.subplot(121)
    plt.imshow(img)
    plt.subplot(122)
    plt.imshow(img_corrected)
    plt.show()

    import cv2
    import numpy as np
    
    img = cv2.imread("G:\MyLearning\TensorFlow_deep_learn\data\lena.jpg")
    M_copy_img = np.array([[0, 0.8, -200],[0.8, 0, -100]], dtype=np.float32)
    img_change = cv2.warpAffine(img, M_copy_img,(300,300))
    cv2.imshow("test",img_change)
    cv2.waitKey(0)

    import cv2
    import random
    
    img = cv2.imread("G:\MyLearning\TensorFlow_deep_learn\data\lena.jpg")
    width,height,depth = img.shape
    img_width_box = width * 0.2
    img_height_box = height * 0.2
    for _ in range(9):
        start_pointX = random.uniform(0, img_width_box)
        start_pointY = random.uniform(0, img_height_box)
        copyImg = img[int(start_pointX):200, int(start_pointY):200]
        cv2.imshow("test", copyImg)
        cv2.waitKey(0)
    import cv2
    
    img = cv2.imread("G:\MyLearning\TensorFlow_deep_learn\data\lena.jpg")
    rows,cols,depth = img.shape
    img_change = cv2.getRotationMatrix2D((cols/2,rows/2),45,1)
    res = cv2.warpAffine(img,img_change,(rows,cols))
    cv2.imshow("test",res)
    cv2.waitKey(0)

    import cv2
    import  numpy as np
    
    img = cv2.imread("G:\MyLearning\TensorFlow_deep_learn\data\lena.jpg")
    img_hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
    turn_green_hsv = img_hsv.copy()
    turn_green_hsv[:,:,0] = (turn_green_hsv[:,:,0] + np.random.random() ) % 180
    turn_green_hsv[:,:,1] = (turn_green_hsv[:,:,1] + np.random.random() ) % 180
    turn_green_hsv[:,:,2] = (turn_green_hsv[:,:,2] + np.random.random() ) % 180
    turn_green_img = cv2.cvtColor(turn_green_hsv,cv2.COLOR_HSV2BGR)
    cv2.imshow("test",turn_green_img)
    cv2.waitKey(0)

    import cv2
    
    def on_mouse(event, x, y, flags, param):
        rect_start = (0,0)
        rect_end = (0,0)
        if event == cv2.EVENT_LBUTTONDOWN:
            rect_start = (x,y)
        if event == cv2.EVENT_LBUTTONUP:
            rect_end = (x, y)
        cv2.rectangle(img, rect_start, rect_end,(0,255,0), 2)
        
    img = cv2.imread("G:\MyLearning\TensorFlow_deep_learn\data\lena.jpg")
    cv2.namedWindow('test')
    cv2.setMouseCallback("test",on_mouse)
    while(1):
        cv2.imshow("test",img)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cv2.destroyAllWindows()

  • 相关阅读:
    C语言和go语言之间的交互
    Elasticsearch笔记九之优化
    Elasticsearch笔记八之脑裂
    Elasticsearch笔记七之setting,mapping,分片查询方式
    Elasticsearch笔记六之中文分词器及自定义分词器
    Elasticsearch笔记四之配置参数与核心概念
    Elasticsearch笔记三之版本控制和插件
    Elasticsearch笔记二之Curl工具基本操作
    Elasticsearch笔记五之java操作es
    Python处理Excel表格
  • 原文地址:https://www.cnblogs.com/tszr/p/10356003.html
Copyright © 2020-2023  润新知