当前位置: 首页>>代码示例>>C++>>正文


C++ cv::namedWindow方法代码示例

本文整理汇总了C++中cv::namedWindow方法的典型用法代码示例。如果您正苦于以下问题:C++ cv::namedWindow方法的具体用法?C++ cv::namedWindow怎么用?C++ cv::namedWindow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv的用法示例。


在下文中一共展示了cv::namedWindow方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: viewShapeModel

void ShapeModel::viewShapeModel()
{
    int q1, q2;
    static ModelViewInfo vData;
    vData.vList.resize(this->nShapeParams, 30/2);
    vData.pModel = this;
    vData.curParam = 0;
    viewShapeModelUpdate(&vData);
    q1 = 15;
    q2 = 0;
    namedWindow("Viewing Shape Model", CV_WINDOW_AUTOSIZE);
    createTrackbar("param value", "Viewing Shape Model", 
                   &q1, 30, &viewShapeUpdateValue, &vData);
    createTrackbar("which param", "Viewing Shape Model", 
                   &q2, nShapeParams-1, &viewShapeUpdateCurParam, &vData);
}
开发者ID:bweldon,项目名称:CSCI-448-Group-Project,代码行数:16,代码来源:shapemodel.cpp

示例2: Setup

void FingerTracker::Setup()
{
	VideoCapture capture(0);
	if (!capture.isOpened())
	{
		throw std::runtime_error("Could not start camera capture");
	}

	int windowSize = 25;
	int Xpos = 200;
	int Ypos = 50;
	int update = 0;
	int buttonClicked = 0;
	namedWindow("RGB", CV_WINDOW_AUTOSIZE);
	createTrackbar("X", "RGB",  &Xpos, 320, TrackBarCallback, (void*)&update);
	createTrackbar("Y", "RGB",  &Ypos, 240, TrackBarCallback, (void*)&update);
	createTrackbar("Size", "RGB",  &windowSize, 100, TrackBarCallback, (void*)&update);
	setMouseCallback("RGB", MouseCallback, (void*)&buttonClicked);
	Mat fingerWindowBackground, fingerWindowBackgroundGray;

	m_calibrationData.reset(new CalibrationData());
	bool ticking = false;
	std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
    while (true)
	{  		
		Mat frame, frameHSV;

		if (capture.read(frame))
		{
			flip(frame, frame, 1);

			pyrDown(frame, frame, Size(frame.cols / 2, frame.rows / 2));

			Rect fingerWindow(Point(Xpos, Ypos), Size(windowSize, windowSize*3));
			if (Xpos + windowSize >= frame.cols || Ypos + windowSize*3 >= frame.rows)
			{
				windowSize = 20;
				Xpos = 200;
				Ypos = 50;
				update = 0;
			}
			else if (buttonClicked == 1)
			{
				frame(fingerWindow).copyTo(fingerWindowBackground);
				cvtColor(fingerWindowBackground, fingerWindowBackgroundGray, CV_BGR2GRAY);
				buttonClicked  = 0;
				update = 0;
				cvDestroyAllWindows();
			}

			if (fingerWindowBackgroundGray.rows && !m_calibrationData->m_ready)
			{
				Mat diff, thd;
				absdiff(frame(fingerWindow), fingerWindowBackground, diff);
				std::vector<Mat> ch;
				split(diff, ch);
				threshold(ch[0], ch[0], m_calibrationDiffThreshold, 255, 0);
				threshold(ch[1], ch[1], m_calibrationDiffThreshold, 255, 0);
				threshold(ch[2], ch[2], m_calibrationDiffThreshold, 255, 0);
				thd = ch[0];
				add(thd, ch[1], thd);
				add(thd, ch[2], thd);
				medianBlur(thd, thd, 5);

				Mat top, middle, bottom;
				Rect r1 = Rect(0, 0, thd.cols, thd.rows/3);
				Rect r2 = Rect(0, thd.rows / 3 + 1, thd.cols, thd.rows/3);
				Rect r3 = Rect(0, thd.rows * 2 / 3 + 1, thd.cols, thd.rows -  thd.rows * 2 / 3 - 1);
				top = thd(r1);
				middle = thd(r2);
				bottom = thd(r3);			

				auto percentageTop = countNonZero(top) * 100.0 / top.size().area();
				auto percentageMiddle = countNonZero(middle) * 100.0 / middle.size().area();
				auto percentageBottom = countNonZero(bottom) * 100.0 / bottom.size().area();

				bool topReady = false;
				bool middleReady = false;
				bool bottomReady = false;

				Scalar c1, c2, c3;
				if (percentageTop > m_calibrationTopLowerThd && percentageTop < m_calibrationTopUpperThd)
				{
					topReady = true;
					c1 = Scalar(0, 255, 255);
				}
				else
				{
					c1 = Scalar(0, 0, 255);
				}

				if (percentageMiddle > m_calibrationMiddleLowerThd && percentageMiddle < m_calibrationMiddleUppperThd)
				{
					middleReady = true;					
					c2 = Scalar(0, 255, 255);
				}
				else
				{
					c2 = Scalar(0, 0, 255);
				}
//.........这里部分代码省略.........
开发者ID:brejski,项目名称:FingerTracking,代码行数:101,代码来源:FingerTracker.cpp

示例3: main


//.........这里部分代码省略.........
        cvtColor(im0, im0_gray, CV_BGR2GRAY);

        //Initialize cmt
        cmt.initialize(im0_gray, rect);

        //Write init region to output file
        ofstream output_file("output.txt");
        output_file << rect.x << ',' << rect.y << ',' << rect.width << ',' << rect.height << std::endl;

        //Process images, write output to file
        for (size_t i = 1; i < files.size(); i++)
        {
            FILE_LOG(logINFO) << "Processing frame " << i << "/" << files.size();
            Mat im = imread(files[i]);
            Mat im_gray;
            cvtColor(im, im_gray, CV_BGR2GRAY);
            cmt.processFrame(im_gray);
            if (verbose_flag)
            {
                display(im, cmt);
            }
            rect = cmt.bb_rot.boundingRect();
            output_file << rect.x << ',' << rect.y << ',' << rect.width << ',' << rect.height << std::endl;
        }

        output_file.close();

        return 0;
    }

    //Normal mode

    //Create window
    namedWindow(WIN_NAME);

    VideoCapture cap;

    bool show_preview = true;

    //If no input was specified
    if (input_path.length() == 0)
    {
        cap.open(0); //Open default camera device
    }

    //Else open the video specified by input_path
    else
    {
        cap.open(input_path);

        if (skip_frames > 0)
        {
          cap.set(CV_CAP_PROP_POS_FRAMES, skip_frames);
        }

        if (skip_msecs > 0)
        {
          cap.set(CV_CAP_PROP_POS_MSEC, skip_msecs);

          // Now which frame are we on?
          skip_frames = (int) cap.get(CV_CAP_PROP_POS_FRAMES);
        }

        show_preview = false;
    }
开发者ID:tesYolan,项目名称:CppMT,代码行数:66,代码来源:main.cpp

示例4: main

int main(int argc, char **argv)
{
    CMT cmt;
    Rect rect;
    
    FILELog::ReportingLevel() = logINFO; // = logDEBUG;
    Output2FILE::Stream() = stdout; //Log to stdout

    // openCV window
    namedWindow(WIN_NAME);

    // libuvc variables
    uvc_context *ctx = NULL;
    uvc_device_t *dev = NULL;
    uvc_device_handle_t *handle = NULL;
    uvc_stream_ctrl_t ctrl;
    uvc_error_t res;

    // create a UVC context
    res = uvc_init(&ctx, NULL);
    uvc_error(res, "init");

    // search for the Intel camera specifically
    res = uvc_find_device(ctx, &dev, 0x8086, 0x0a66, NULL);
    uvc_error(res, "find_device");

    // open the camera device
    res = uvc_open(dev, &handle);
    uvc_error(res, "open2");

    //uvc_print_diag(handle, stderr);

    // configure the stream format to use
    res = uvc_get_stream_ctrl_format_size(handle, &ctrl, UVC_FRAME_FORMAT_YUYV, W, H, FPS);
    uvc_perror(res, "get_stream");

    //uvc_print_stream_ctrl(&ctrl, stderr);

    // OpenCV matrix for storing the captured image data, CV_8UC3
    // means 8-bit Unsigned Char, 3 channels per pixel.
    Mat im;
    im.create( H, W, CV_8UC3);

    image_data = malloc(W*H*3);

    // start streaming data from the camera
    printf("Start streaming...\n");
    res = uvc_start_streaming(handle, &ctrl, uvc_callback, (void*)&cmt, 0);
    uvc_error(res, "start_streaming");
    
    // wait until the first frame has arrived so it can be used for previewing
    printf("Waiting for first frame...\n");
    while(!got_first_frame)
        usleep(10000);

    // grab the data for the captured frame
    memcpy(im.data, image_data, W*H*3);

    // display it in OpenCV and select a region to track
    rect = getRect(im, WIN_NAME);
    printf("Bounding box: %d,%d+%dx%d\n", rect.x, rect.y, rect.width, rect.height);

    // convert to suitable format for CMT if needed
    Mat im0_gray;
    if (im.channels() > 1) 
        cvtColor(im, im0_gray, CV_BGR2GRAY);
    else 
        im0_gray = im;

    cmt.initialize(im0_gray, rect);
    printf("Main loop starting\n");

    int frame = 0;
    while (true)
    {
        frame++;

        // grab the data for the captured frame
        memcpy(im.data, image_data, W*H*3);

        Mat im_gray;
        if (im.channels() > 1) 
            cvtColor(im, im_gray, CV_BGR2GRAY);
        else
            im_gray = im;

        cmt.processFrame(im_gray);
       
        printf("#%d, active: %lu\n", frame, cmt.points_active.size());
        char key = display(im, cmt);
        if(key == 'q')
            break;
    }

    uvc_stop_streaming(handle);

    free(image_data);

    uvc_close(handle);
    uvc_unref_device(dev);
//.........这里部分代码省略.........
开发者ID:andrewramsay,项目名称:cmt-uvc-realsense,代码行数:101,代码来源:main.cpp


注:本文中的cv::namedWindow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。