zoukankan      html  css  js  c++  java
  • opencv练习

    //图像的二值化
    
    #include <opencv2/opencv.hpp>
    using namespace std;
    
    
    
    IplImage *g_pGrayImage = NULL;
    IplImage *g_pBinaryImage = NULL;
    const char *pstrWindowsBinaryTitle = "二值图";
    
    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 = "原图";
    	const char *pstrWindowsToolBarName = "二值图阈值";
    
    	// 从文件中加载原图
    	IplImage *pSrcImage = cvLoadImage("C:\Users\Administrator\Desktop\001.jpg", 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;
    }
    

      本人初学者,仅供参考

  • 相关阅读:
    OAF_OAF控件系列9
    OAF_OAF控件系列8
    OAF_OAF控件系列7
    OAF_OAF控件系列5
    OAF_OAF控件系列4
    OAF_OAF控件系列3
    OAF_OAF控件系列3
    OAF_OAF控件系列2
    OAF_OAF控件系列1
    PLSQL_性能优化索引Index介绍(概念)
  • 原文地址:https://www.cnblogs.com/intruder/p/12072397.html
Copyright © 2011-2022 走看看