2019-06-23(day011——python中正则化时要将

2019-06-23  本文已影响0人  雨住多一横

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中的新知识

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++中的新知识

上一篇 下一篇

猜你喜欢

热点阅读