2019-06-23(day011)

python

import cv2 as cv
import numpy as np
import sys
sys.path.append("../")
import my_module as m
def function():
    img = m.read("test.jpg")
    cv.imshow("input", img)
    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
    
    gray = np.float32(gray)
    
    dst = np.zeros(gray.shape, dtype = np.float32)
    cv.normalize(gray, dst = dst, alpha = 0, beta = 1.0, norm_type = cv.NORM_MINMAX)
    print(dst)
    cv.imshow("min_max", np.uint8(dst * 255))
    
    dst = np.zeros(gray.shape, dtype = np.float32)
    cv.normalize(gray, dst = dst, alpha = 1.0, beta = 0, norm_type = cv.NORM_INF)
    print(dst)
    cv.imshow("INF", np.uint8(dst * 255))
    
    dst = np.zeros(gray.shape, dtype = np.float32)
    cv.normalize(gray, dst = dst, alpha = 1.0, beta = 0, norm_type = cv.NORM_L1)
    print(dst)
    cv.imshow("L1", np.uint8(dst * 10000000))
    
    dst = np.zeros(gray.shape, dtype = np.float32)
    cv.normalize(gray, dst = dst, alpha = 1.0, beta = 0, norm_type = cv.NORM_L2)
    print(dst)
    cv.imshow("L2", np.uint8(dst * 10000))
function()
cv.waitKey(0)
cv.destroyAllWindows()

python中的新知识

  • np.float32()
  • np.uint8
  • cv.NORM_MINMAX
  • cv.NORM_INF
  • cv.NORM_L1
  • cv.NORM_L2
  • cv.normalize()
    从上面程序看出,python中正则化时要将Mat中的数据转化为np.float32,处理完之后,显示之前需要再转化为np.uint8

c++

#include "all.h"
using namespace std;
using namespace cv;

void MyClass::day011() {
    Mat img = read(PATH + "images\\test.jpg");
    Mat gray;
    if (img.empty()) {
        printf("can't open image\n");
        return;
    }
    cvtColor(img, gray, COLOR_BGR2GRAY);
    gray.convertTo(gray, CV_32F);

    Mat dst = Mat::zeros(gray.size(), CV_32FC1);
    normalize(gray, dst, 1.0, 0, NORM_MINMAX);
    dst = dst * 255;
    dst.convertTo(dst, CV_8UC1);
    imshow("minMax", dst);

    dst = Mat::zeros(gray.size(), CV_32FC1);
    normalize(gray, dst, 1.0, 0, NORM_INF);
    dst = dst * 255;
    dst.convertTo(dst, CV_8UC1);
    imshow("INF", dst);

    dst = Mat::zeros(gray.size(), CV_32FC1);
    normalize(gray, dst, 1.0, 0, NORM_L1);
    dst = dst * 10000000;
    dst.convertTo(dst, CV_8UC1);
    imshow("L1", dst);

    dst = Mat::zeros(gray.size(), CV_32FC1);
    normalize(gray, dst, 1.0, 0, NORM_L2);
    dst = dst * 10000;
    dst.convertTo(dst, CV_8UC1);
    imshow("L2", dst);
    waitKey(0);
}

c++中的新知识

  • 新数据类型:CV_32FC1
  • NORM_MINMAC
  • NORM_INF
  • NORM_L1
  • NORM_L2
  • normalize()
  • Mat::convertTo()
    从上面程序看出,c++中正则化时要将Mat中的数据转化为CV_32F,处理完之后,显示之前需要再转化为CV_8U
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值