2019-06-23(day010)

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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值