亲测可用:opencv3+vs2013 阈值化操作 二值化阈值 反二值化 截断阈值

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
#define  Window_name "程序窗口"
//全局变量声明
int g_nThresholdValue =100;//
int g_nThresholdType = 3;//
Mat g_srcImage, g_grayImage, g_dstImage;
//轨迹条回调函数
static void on_Threshold(int, void*);
int main(){
    system("color 5E");
    g_srcImage= imread("靶标原图.png", 1);
    if (!g_srcImage.data){
        printf("打开图片错误,请检查路径\n");
        return false;
    }
    cvtColor(g_srcImage, g_grayImage, COLOR_RGB2GRAY);
    namedWindow("原图窗口", 1);
    imshow("原图窗口", g_srcImage);
    //新建两个bar
    namedWindow(Window_name, WINDOW_AUTOSIZE);
    createTrackbar("模式", Window_name, &g_nThresholdType, 4, on_Threshold);
    createTrackbar("参数值", Window_name, &g_nThresholdValue, 255, on_Threshold);
    //初始化阈值回调函数
    on_Threshold(0, 0);
    while (1)
    {
        int key;
        key = waitKey(20);
        if ((char)key==27)
            break;
    }
        return 0;
}
static void on_Threshold(int, void*){
    threshold(g_srcImage,g_dstImage,g_nThresholdValue,255,g_nThresholdType);
    imshow(Window_name, g_dstImage);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值