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 @ 2017-10-30 01:19  scott_h  阅读(32)  评论(0编辑  收藏  举报