5、滚动条

滚动条

// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include 
#include 
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"



using namespace std;
using namespace cv;


//膨胀腐蚀参数
struct data {

    int dilatea1 = 17;
    int dilatea2 = 11;
    int dilateb1 = 6;
    int dilateb2 = 1;

    int erodea1 = 1;
    int erodea2 = 11;
    int erodeb1 = 6;
    int erodeb2 = 6;

}mydata22;


struct data mydata;

//滚动条
void Erosion(int sum, void* dat)
{

    //string* p = static_cast(data);

    //String str = *(String *)dat;


   //int pp = *(int *) dat;

    const char*pp = (char *)dat;

    if (strcmp(pp, "e")==0)
    {
        cout << "字符ee:" << *pp << endl;

        mydata.dilatea1 = sum * 2 + 1;
    }

    /*if (pp==(char)"e") {
        cout << "字符ee:" << pp << endl;
    }*/

    cout << "字符:"<< pp <<endl;

    cout << "滚动值1:" << sum << endl;

   /* int num1= getTrackbarPos("dilatea1","ErosionDemo");
    int num = getTrackbarPos("erodea1", "ErosionDemo");
    cout << "滚动值1:" << num<
    /* cout << "滚动值:" << star << endl;*/

}


void main(int argc, char* argv[])
{
    //定义是否缺陷的变量;
    bool isDefect = false;
    int star2 = 3;

    //显示多张图
    vector<Mat> imageVector;
    Mat src, image1, image2, image3, image4, image5, image6, dst;

    膨胀腐蚀参数
    //struct data {

    //    int dilatea1 = 17;
    //    int dilatea2 = 11;
    //    int dilateb1 = 6;
    //    int dilateb2 = 1;

    //    int erodea1 = 1;
    //    int erodea2 = 11;
    //    int erodeb1 = 6;
    //    int erodeb2 = 6;

    //}mydata;

    int i = 2;

    string test = "gogoo";
    //滚动条
    namedWindow("ErosionDemo", WINDOW_NORMAL);
    createTrackbar("dilatea1", "ErosionDemo", &mydata.dilatea1, 30, Erosion,(void *) "e");
    createTrackbar("dilatea2", "ErosionDemo", &mydata.dilatea2, 30, Erosion,(void *) "g");
    createTrackbar("dilateb1", "ErosionDemo", &mydata.dilateb1, 30, Erosion,(void *) "n");
    createTrackbar("dilateb2", "ErosionDemo", &mydata.dilateb2, 30, Erosion,(void *) "d");
                                                                          
   /* createTrackbar("erodea1", "ErosionDemo", &mydata.erodea1, 30, Erosion);
    createTrackbar("erodea2", "ErosionDemo", &mydata.erodea2, 30, Erosion);
    createTrackbar("erodeb1", "ErosionDemo", &mydata.erodeb1, 30, Erosion);
    createTrackbar("erodeb2", "ErosionDemo", &mydata.erodeb2, 30, Erosion);*/
                                      
    //setTrackbarPos("erodea1", "ErosionDemo",10);
    //setTrackbarPos("erodea2", "ErosionDemo", 11);
    //Erosion(0, 0);//轨迹条回调函数    

  /*  int num1 = getTrackbarPos("dilatea1", "ErosionDemo");
    int num = getTrackbarPos("erodea1", "ErosionDemo");
    cout << "滚动值1:" << num << endl;
    cout << "滚动值2:" << num1 << endl;*/
    waitKey(2);

    while (true)
    {
        
            //cout << "数据:"<< mydata.dilatea1 <

            /*调试参数*/
            cout << " dilatea1: " << mydata.dilatea1
                << " dilatea2: " << mydata.dilatea2
                << " dilateb1: " << mydata.dilateb1
                << " dilateb2: " << mydata.dilateb2

                /*<< " erodea1: " << mydata.erodea1
                << " erodea2: " << mydata.erodea2
                << " erodeb1: " << mydata.erodeb1
                << " erodeb2: " << mydata.erodeb2*/


                << endl;

            waitKey(1500);

    }


}


// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件

5、滚动条_第1张图片

你可能感兴趣的:(opencv基础操作,opencv,人工智能,计算机视觉)