OpenCV 渲染视频, 显示摄像头

如果从摄像头读取 image帧,如何显示到各个OS平台的 原生界面窗口上?

  • windows
    - 1.用d3d9,d3d10,d3d11 用DirectX来渲染,支持CPU,GPU, 参见OpenCV 官方sample
    - 2.创建 nameWindow ,用这个Windows 窗口指针HWND 的Handle , 来当作MFC 你显示窗口的子窗口。 用imshow 显示(但需要waitKey 刷新)
https://stackoverflow.com/questions/5217519/what-does-opencvs-cvwaitkey-function-do
cvWaitKey(x) / cv::waitKey(x) does two things:
It waits for x milliseconds for a key press. If a key was pressed during that time, it returns the key's ASCII code. Otherwise, it returns -1.
It handles any windowing events, such as creating windows with cv::namedWindow(), or showing images with cv::imshow().
A common mistake for opencv newcomers is to call cv::imshow() in a loop through video frames, without following up each draw with cv::waitKey(30). In this case, nothing appears on screen, because highgui is never given time to process the draw requests from cv::imshow().
https://docs.opencv.org/3.0-beta/modules/highgui/doc/user_interface.html
imshow需要waitkey 来刷新窗口,是 highgui里面实现的问题。
Displays an image in the specified window.
C++: void imshow(const String& winname, InputArray mat)
Python: cv2.imshow(winname, mat) → None
C: void cvShowImage(const char* name, const CvArr* image)
Parameters:
winname – Name of the window.
image – Image to be shown.
The function imshow displays an image in the specified window. If the window was created with the CV_WINDOW_AUTOSIZE flag, the image is shown with its original size. Otherwise, the image is scaled to fit the window. The function may scale the image, depending on its depth:
If the image is 8-bit unsigned, it is displayed as is.
If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the value range [0,255*256] is mapped to [0,255].
If the image is 32-bit floating-point, the pixel values are multiplied by 255. That is, the value range [0,1] is mapped to [0,255].
If window was created with OpenGL support, imshow also support ogl::Buffer , ogl::Texture2D and cuda::GpuMat as input.
Note This function should be followed by waitKey function which displays the image for specified milliseconds. Otherwise, it won’t display the image. For example, waitKey(0) will display the window infinitely until any keypress (it is suitable for image display). waitKey(25) will display a frame for 25 ms, after which display will be automatically closed. (If you put it in a loop to read videos, it will display the video frame-by-frame)
- 3.用GDI画图
  • linux
    - Qt 同上 2
posted @   scott_h  阅读(33)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示