我无法移动TrackBar

时间:2017-03-30 07:46:25

标签: c++ opencv

我正在编写用于播放视频的opencv源代码。我想添加trackBar并调整视频速度。但是,TrackBar不会移动。我无法专注于视频窗口。这是我的代码OpenCv C ++。我该怎么办?

void onTrackbarSlide(int pos, void *){
    sec = 1;
    sec /= pos;
    printf("pos = %d\n",pos);

}

int main(void)
{
    strcat(InputFile, FileName);            // input video file

    //VideoCapture cap(0);          // Create an object and open the default(0) camera. C++ Syntax: VideoCapture::VideoCapture(int device)
    VideoCapture cap;                   // Class for video capturing from video files or cameras.

    cap.open(InputFile);                // Open video file or a capturing device for video capturing

    if (!cap.isOpened()) {              // Check if the file is opened sucessfully.
        printf("\nFail to open a video file");
        return -1;
    }

    // When querying a property that is not supported by the backend used by the VideoCapture class, value 0 is returned.
    double fps = cap.get(CV_CAP_PROP_FPS);  printf("\nCV_CAP_PROP_FPS = %f", fps);
    double ToTalFrames = cap.get(CV_CAP_PROP_FRAME_COUNT);  printf("\nCV_CAP_PROP_FRAME_COUNT = %f", fps);

    CvSize  FrameSize;

    FrameSize.width = (int)cap.get(CV_CAP_PROP_FRAME_WIDTH);
    FrameSize.height = (int)cap.get(CV_CAP_PROP_FRAME_HEIGHT);
    printf("\nWidth * Height = %d * %d\n", FrameSize.width, FrameSize.height);

    VideoWriter wrt;


#define CODEC -1


    namedWindow("original", 1);

    int slider_position = 0;
    int slider_max = 255;

    createTrackbar("video speed", "original", &slider_position, slider_max, onTrackbarSlide);

    wrt.open(OutputFile, CODEC, fps, FrameSize);

    Mat frame, dst1;
    Mat dst2;



    for (int i = 1; i< ToTalFrames; i++)
    {
        cap.read(frame);
        if (frame.data == NULL) { printf("\nNo image found!\n"); return(0); }
        imshow("original", frame);

        if( waitKey(sec /fps) == 0x1b ) break;          // Break if key input is escape code.

    }
    return 0;
}

0 个答案:

没有答案