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


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

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


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

示例1: Display

void FingerTracker::Display(Mat frame, Candidate candidate) const
{
	if (candidate.m_found)
	{
		rectangle(frame, candidate.m_windowRect.tl(), candidate.m_windowRect.br(), Scalar(0, 255, 255));
		rectangle(frame, candidate.m_fingerPosition - Point(2,2), candidate.m_fingerPosition + Point(2,2), Scalar(255, 0, 0), 2);
	}
#if ENABLE_LINE_DRAWING
	Point prev(-1,-1);
	for (auto point : m_points)
	{
		if (prev.x != -1)
		{
			line(frame, prev, point, Scalar(0, 255, 0));
		}
		prev = point;
	}

#endif
	imshow("Camera", frame);
}
开发者ID:brejski,项目名称:FingerTracking,代码行数:21,代码来源:FingerTracker.cpp

示例2: capture


//.........这里部分代码省略.........
					bottomReady = true;
					c3 = Scalar(0, 255, 255);
				}
				else
				{
					c3 = Scalar(0, 0, 255);
				}

				bool readyToGo = false;
				if (middleReady && topReady && bottomReady)
				{
					c1 = Scalar(0, 255, 0);
					c2 = Scalar(0, 255, 0);
					c3 = Scalar(0, 255, 0);
					if (!ticking)
					{
						start = std::chrono::system_clock::now();
						ticking = true;
					}
					if (std::chrono::system_clock::now() - start > std::chrono::seconds(1))
					{
						readyToGo = true;
					}
				}
				else
				{
					ticking = false;
				}

#if ENABLE_DEBUG_WINDOWS
				std::stringstream ss;
				ss << percentageTop << ", " << percentageMiddle << ", " << percentageBottom;
				putText(frame, ss.str(), Point(0, getTextSize(ss.str(), 0, 0.5, 1, nullptr).height), 0, 0.5, Scalar::all(255), 1);
				cv::imshow("Thresholded", thd);
#endif

				if (percentageTop >= m_calibrationTopUpperThd && percentageBottom >= m_calibrationBottomUpperThd && percentageMiddle >= m_calibrationMiddleUppperThd)
				{
					putText(frame, "Move finger away from camera", Point(0, getTextSize("Move finger away from camera", 0, 0.5, 1, nullptr).height), 0, 0.5, Scalar::all(255), 1);
				}
				else if (percentageTop <= m_calibrationTopLowerThd && percentageBottom <= m_calibrationBottomLowerThd && percentageMiddle <= m_calibrationMiddleLowerThd)
				{
					putText(frame, "Move finger closer to camera", Point(0, getTextSize("Move finger closer to camera", 0, 0.5, 1, nullptr).height), 0, 0.5, Scalar::all(255), 1);
				}
				
				if (readyToGo)
				{
					Mat framePatchHSV;
					cvtColor(frame(fingerWindow), framePatchHSV, CV_BGR2HSV);
					cvtColor(frame, frameHSV, CV_BGR2HSV);

					MatND hist;
					calcHist(&framePatchHSV, 1, m_calibrationData->m_channels, thd, hist, 2, m_calibrationData->m_histSize, (const float**)m_calibrationData->m_ranges, true, false);
					m_calibrationData->m_hist = hist;
					normalize(m_calibrationData->m_hist, m_calibrationData->m_hist, 0, 255, NORM_MINMAX, -1, Mat());

#if ENABLE_DEBUG_WINDOWS

					double maxVal=0;
					minMaxLoc(m_calibrationData->m_hist, 0, &maxVal, 0, 0);
					int scale = 10;
					Mat histImg = Mat::zeros(m_calibrationData->m_sbins*scale, m_calibrationData->m_hbins*10, CV_8UC3);
					for( int h = 0; h < m_calibrationData->m_hbins; h++)
					{
						for( int s = 0; s < m_calibrationData->m_sbins; s++ )
						{
开发者ID:brejski,项目名称:FingerTracking,代码行数:67,代码来源:FingerTracker.cpp

示例3: Process

void FingerTracker::Process(Mat frame)
{
#if ENABLE_DEBUG_WINDOWS
	Mat img_display;
	frame.copyTo(img_display);
#endif
	
	//	Process only Region of Interest i.e. region around current finger position
	Rect roi = Rect(		
		Point(std::max(m_currentCandidate.m_windowRect.tl().x - m_roiSpanX, 0), std::max(m_currentCandidate.m_windowRect.tl().y - m_roiSpanY, 0)), 		
		Point(std::min(m_currentCandidate.m_windowRect.tl().x + m_roiSpanX + m_calibrationData->m_fingerPatch.cols, frame.cols), 
			  std::min(m_currentCandidate.m_windowRect.tl().y + m_roiSpanY + m_calibrationData->m_fingerPatch.rows, frame.rows)));

	Mat frameRoi;
	frame(roi).copyTo(frameRoi);

	//================TEMPLATE MATCHING
	int result_cols =  frameRoi.cols - m_calibrationData->m_fingerPatch.cols + 1;
	int result_rows = frameRoi.rows - m_calibrationData->m_fingerPatch.rows + 1;
	assert(result_cols > 0 && result_rows > 0);

	Mat scoreMap;
	scoreMap.create(result_cols, result_rows, CV_32FC1);

	//	Compare current frame roi region to known candidate
	//	Using OpenCV matchTemplate function with correlation coefficient matching method
	matchTemplate(frameRoi, m_calibrationData->m_fingerPatch, scoreMap, 3);

	//================HISTOGRAM BACK PROJECTION
	MatND backProjection;
	Mat frameHSV;
	cvtColor(frameRoi, frameHSV, CV_BGR2HSV);

	calcBackProject(&frameHSV, 1, m_calibrationData->m_channels, m_calibrationData->m_hist, backProjection, (const float**)(m_calibrationData->m_ranges), 1, true);

	Mat backProjectionThresholded;
	threshold(backProjection, backProjectionThresholded, m_backProjectionThreshold, 255, 0);
	erode(backProjectionThresholded, backProjectionThresholded, getStructuringElement(MORPH_RECT, Size(2 * m_erosionSize + 1, 2 * m_erosionSize + 1), Point(m_erosionSize, m_erosionSize)));
	dilate(backProjectionThresholded, backProjectionThresholded, getStructuringElement(MORPH_RECT, Size(2 * m_dilationSize + 1, 2 * m_dilationSize + 1), Point(m_dilationSize, m_dilationSize)));

	Mat backProjectionThresholdedShifted;
	Rect shifted(Rect(m_calibrationData->m_fingerPatch.cols - 1, m_calibrationData->m_fingerPatch.rows - 1, scoreMap.cols, scoreMap.rows));
	backProjectionThresholded(shifted).copyTo(backProjectionThresholdedShifted);

	Mat maskedOutScoreMap(scoreMap.size(), CV_8U);
	scoreMap.copyTo(maskedOutScoreMap, backProjectionThresholdedShifted);

	//====================Localizing the best match with minMaxLoc
	double minVal; double maxVal; Point minLoc; Point maxLoc;
	Point matchLoc;
	minMaxLoc(maskedOutScoreMap, &minVal, &maxVal, &minLoc, &maxLoc, Mat());
	matchLoc = maxLoc + roi.tl();

	m_currentCandidate.m_confidence = static_cast<float>(maxVal);

	if (maxVal > m_candidateDetecionConfidenceThreshold)
	{
		m_currentCandidate.m_found = true;
		m_currentCandidate.m_windowRect = Rect(matchLoc, Point(matchLoc.x + m_calibrationData->m_fingerPatch.cols , matchLoc.y + m_calibrationData->m_fingerPatch.rows));		

		//================Find finger position
		Mat fingerWindowThresholded;
		backProjectionThresholded(Rect(maxLoc, Point(maxLoc.x + m_calibrationData->m_fingerPatch.cols , maxLoc.y + m_calibrationData->m_fingerPatch.rows))).copyTo(fingerWindowThresholded);
		
		m_currentCandidate.m_fingerPosition = GetFingerTopPosition(fingerWindowThresholded) + matchLoc;

#if ENABLE_DEBUG_WINDOWS
		rectangle(img_display, m_currentCandidate.m_windowRect.tl(), m_currentCandidate.m_windowRect.br(), Scalar(255,0,0), 2, 8, 0 );
		rectangle(scoreMap, m_currentCandidate.m_windowRect.tl(), m_currentCandidate.m_windowRect.br(), Scalar::all(0), 2, 8, 0 );
		rectangle(img_display, m_currentCandidate.m_fingerPosition, m_currentCandidate.m_fingerPosition + Point(5,5), Scalar(255,0,0));
#endif
	}
	else
	{
		m_currentCandidate.m_found = false;
	}

#if ENABLE_DEBUG_WINDOWS
	std::stringstream ss;
	ss << maxVal;
	putText(img_display, ss.str(), Point(50, 50), 0, 0.5, Scalar(255,255,255), 1);

	imshow("Overlays", img_display);
	imshow("Results", scoreMap);
	imshow("ResultMasked", maskedOutScoreMap);
#endif
}
开发者ID:brejski,项目名称:FingerTracking,代码行数:87,代码来源:FingerTracker.cpp

示例4: main


//.........这里部分代码省略.........
    {
        cout << static_cast<int>(id) << " ";
    }
    cout << endl;

    for (const auto &id : ids)
    {
        vector<uint8_t> raw;
        PacketType type;

        cout << "examining " << static_cast<int>(id) << endl;

        for (const auto &pkt : pkts)
        {
            if (pkt.getID() == id)
            {
                size_t new_length = pkt.getOffset() +
                    static_cast<size_t>(pkt.getLength());

                type = pkt.getType();

                if (new_length > raw.size())
                {
                    raw.resize(new_length, 0);
                }

                for (size_t k = 0; k < pkt.getLength(); k++)
                {
                    raw[pkt.getOffset() + k] = pkt.getData()[k];
                }
            }
        }

        cout << "type: " << type << endl;

        cout << hex;
        for (size_t j = 0; j < 512; j++)
        {
            if (j > 0 && (j % 32) == 0)
            {
                cout << endl;
            }
            cout << (static_cast<unsigned int>(raw[j]) & 0xFF) << " ";
        }
        cout << endl;

        Mat img{Size(160, 120), CV_8UC3, raw.data()};
        Mat dst;

        //cvtColor(img, dst, CV_YUV2GRAY_UYVY);
        //cvtColor(img, dst, CV_YUV2GRAY_YUY2);
        //cvtColor(img, dst, CV_YUV2BGR_UYVY);
        //cvtColor(img, dst, CV_YUV2BGRA_UYVY);
        //cvtColor(img, dst, CV_YUV2BGR_YUY2);
        //cvtColor(img, dst, CV_YUV2BGR_YVYU);
        //cvtColor(img, dst, CV_YUV2BGRA_YUY2);
        //cvtColor(img, dst, CV_YUV2BGRA_YVYU);
        //cvtColor(img, dst, CV_YUV2GRAY_NV12);
        //cvtColor(img, dst, CV_YUV2BGR_NV12);
        cvtColor(img, dst, CV_YCrCb2BGR);

        imshow("Police Video", dst);
        waitKey(0);

        ofstream out_jpeg{"out.jpg", ofstream::binary};
        for (size_t j = 0; j < raw.size(); j++)
        {
            if (raw[j] == 0xFF && raw[j + 1] == 0xD8)
            {
                cout << "hit the start" << endl;
                out_jpeg.write(reinterpret_cast<char *>(raw.data() + j), 2);
                j++;
            }
            else if (raw[j] == 0xFF && raw[j + 1] == 0xDB)
            {
                cout << "hit the start 2" << endl;
                out_jpeg.write(reinterpret_cast<char *>(raw.data() + j), 2);
                j++;
            }
            else if (raw[j] == 0xFF && raw[j + 1] == 0xC0)
            {
                cout << "hit the start 3" << endl;
                out_jpeg.write(reinterpret_cast<char *>(raw.data() + j), 2);
                j++;
            }
            else if (raw[j] == 0xFF && raw[j + 1] == 0xD9)
            {
                cout << "hit the end" << endl;
                out_jpeg.write(reinterpret_cast<char *>(raw.data() + j), 2);
                return 0;
            }
            else
            {
                out_jpeg.write(reinterpret_cast<char *>(raw.data() + j), 1);
            }
        }
    }

    return 0;
}
开发者ID:alexjlaberge,项目名称:473BodyCam,代码行数:101,代码来源:examine.cpp


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