• 阈值bar


    #include "stdafx.h"
    #include <opencv2/opencv.hpp>
    using namespace std;

    #pragma comment(linker, "/subsystem:"windows" /entry:"mainCRTStartup"")

    IplImage *g_pGrayImage = NULL;
    IplImage *g_pBinaryImage = NULL;
    const char *pstrWindowsBinaryTitle = "二值图(http://blog.csdn.net/MoreWindows)";

    void on_trackbar(int pos)
    {
    // 转为二值图
    cvThreshold(g_pGrayImage, g_pBinaryImage, pos, 255, CV_THRESH_BINARY);
    // 显示二值图
    cvShowImage(pstrWindowsBinaryTitle, g_pBinaryImage);
    }

    int main(int argc, char** argv)
    {
    const char *pstrWindowsSrcTitle = "原图(http://blog.csdn.net/MoreWindows)";
    const char *pstrWindowsToolBarName = "二值图阈值";

    // 从文件中加载原图
    IplImage *pSrcImage = cvLoadImage("E://test1.png", CV_LOAD_IMAGE_UNCHANGED);

    // 转为灰度图
    g_pGrayImage = cvCreateImage(cvGetSize(pSrcImage), IPL_DEPTH_8U, 1);
    cvCvtColor(pSrcImage, g_pGrayImage, CV_BGR2GRAY);

    // 创建二值图
    g_pBinaryImage = cvCreateImage(cvGetSize(g_pGrayImage), IPL_DEPTH_8U, 1);

    // 显示原图
    cvNamedWindow(pstrWindowsSrcTitle, CV_WINDOW_AUTOSIZE);
    cvShowImage(pstrWindowsSrcTitle, pSrcImage);
    // 创建二值图窗口
    cvNamedWindow(pstrWindowsBinaryTitle, CV_WINDOW_AUTOSIZE);

    // 滑动条
    int nThreshold = 0;
    cvCreateTrackbar(pstrWindowsToolBarName, pstrWindowsBinaryTitle, &nThreshold, 254, on_trackbar);

    on_trackbar(1);

    cvWaitKey(0);

    cvDestroyWindow(pstrWindowsSrcTitle);
    cvDestroyWindow(pstrWindowsBinaryTitle);
    cvReleaseImage(&pSrcImage);
    cvReleaseImage(&g_pGrayImage);
    cvReleaseImage(&g_pBinaryImage);
    return 0;
    }

  • 相关阅读:
    bodyparser中间件
    socket编程server端
    快速搭建ELK日志分析系统
    windows下nginx+php-cgi多端口
    c#中bin,obj,properties文件夹的作用
    宝塔面板Linux命令大全
    c#串口编程(转)
    git push.default设置
    PHP在RS232串口通讯协议的应用演示[测试环境WinXP/PHP5.1.4]
    Windows下的串口编程
  • 原文地址:https://www.cnblogs.com/necp-zwl/p/6545921.html
Copyright © 2020-2023  润新知