OpenCV学习笔记——滑动条开关

由于opencv库中并没有专门为开关而设的函数,可以用滑动条做开关

代码:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<highgui.h>
#include<cv.h>
int g_switch_value = 0;
IplImage *img;
void switch_off_fcuntion();
void switch_on_function();
void switch_callback(int position)
{
    if (!position)
    {  
        switch_off_fcuntion();
    }
    else
    {      
        switch_on_function();      
    }
}
int main(void)
{
    cvNamedWindow("sample",1);
    cvCreateTrackbar("Switch", "sample", &g_switch_value, 1, switch_callback);//中间的数值用来自定义可变换区间长度
    while (1)
    {
        if (cvWaitKey(15) == 27)
        {
            cvReleaseImage(&img);
            cvDestroyAllWindows();
            break;
        }
    }
    return 0;
}
void switch_off_fcuntion()
{
    puts("This is q1");
    img = cvLoadImage("q1.jpg", -1);
    cvShowImage("sample", img);
    puts("Q1");
    return;
}
void switch_on_function()
{
    puts("This is q1");
    img = cvLoadImage("q2.jpg", -1);
    cvShowImage("sample", img);
    puts("Q2");
    return;
}

 

posted @   Blackops  阅读(352)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示