美文网首页
2019-06-23(day010)

2019-06-23(day010)

作者: 雨住多一横 | 来源:发表于2019-06-23 17:55 被阅读0次

python

import cv2 as cv
import numpy as np
def function():
    img = cv.imread("../images/flower.jpg", cv.IMREAD_GRAYSCALE)
    cv.imshow("flower", img)
    
    min, max, min_loc, max_loc = cv.minMaxLoc(img)
    print("min: %.2f, max: %.2f" %(min, max))
    print("min loc: ", min_loc)
    print("max loc: ", max_loc)
    
    means, stddev = cv.meanStdDev(img)
    print("mean: %.2f, std_dev: %.2f"%(means, stddev))
    
    img[np.where(img < means)] = 0
    img[np.where(img > means)] = 255
    cv.imshow("binary", img)
function()
cv.waitKey()
cv.destroyAllWindows()

python中的新知识点

  • cv.IMREAD_GRAYSCALE
  • cv.minMaxLoc()
  • 浮点数的格式化输出:%.2f
  • cv.meanStdDev()
  • img[np.where(img < means)] = 0
    img[np.where(img > means)] = 255

c++

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

void MyClass::day010() {
    Mat img1 = read(PATH + "\\images\\test.jpg"), img;
    cvtColor(img1, img, COLOR_BGR2GRAY);
    imshow("input", img);
    double max, min; Point maxLoc, minLoc;
    minMaxLoc(img, &min, &max, &minLoc, &maxLoc, Mat());

    printf("The min value is: %.2f, it's location at (%d, %d)\n", min, minLoc.x, minLoc.y);
    printf("The max value is: %.2f, it's location at (%d, %d)\n", max, maxLoc.x, maxLoc.y);

    Mat means, stdDevs;
    meanStdDev(img1, means, stdDevs);

    printf("The mean(stdDev) of blue channel is %.2f(%.2f)\n", means.at<double>(0, 0), stdDevs.at<double>(0, 0));
    printf("The mean(stdDev) of green channel is %.2f(%.2f)\n", means.at<double>(1, 0), stdDevs.at<double>(1, 0));
    printf("The mean(stdDev) of red channel is %.2f(%.2f)\n", means.at<double>(2, 0), stdDevs.at<double>(2, 0));

    waitKey(0);
}

c++中的新知识点

  • COLOR_BGR2GRAY
  • Point类
  • minMaxLoc()
  • meanStdDev()

相关文章

网友评论

      本文标题:2019-06-23(day010)

      本文链接:https://www.haomeiwen.com/subject/tdlwqctx.html