如何在OpenCV(Python)的视频的同一帧中显示图像?

时间:2019-12-05 19:10:06

标签: python opencv video

我正在尝试在cv2上显示视频,当视频结束时,我想显示和成像。现在我有了这段代码,它可以很好地运行。视频开始播放,当它在新帧上时将其打开以显示图像,但是我想要的是在视频结束时将图像与视频显示在同一帧上。我该如何实现?

import cv2
cap = cv2.VideoCapture('video.mp4')
img = cv2.imread('test.jpg', -1)
if (cap.isOpened() == False):
    print("Error opening video stream or file")
while (cap.isOpened()):
    ret, frame = cap.read()
    if ret == True:
        cv2.imshow('Frame', frame)
        if cv2.waitKey(25) == ord('q'):
            cv2.destroyAllWindows();
            break
    else:
        break
cap.release()
cv2.imshow('image', img)
k = cv2.waitKey(0) & 0xFF
if k == 27:
  cv2.destroyAllWindows()

1 个答案:

答案 0 :(得分:0)

您想在同一窗口中显示img,然后输入相同的名称:

@ECHO OFF
GOTO :Main
:: ======================================================================
:: For each filename in file 'fname', find all that are missing from the
:: directory specified by 'dname'.
::
:: Filenames in 'fname' are one per line, spaces are allowed in a filename.
:: Filenames in 'fname' are relative paths to the directory specified.
::     i.e. to search for files blarg and foo\bar.txt under the directory
::          C:\TEMP
::
::     'fname' will contain
::         blarg
::         foo\bar.txt
::
::     and 'dname' will be passed as C:\TEMP
::
:: Note if the entry in filename matches a directory, that will return success
:: too. This finds missing files and directories.

:Main
SETLOCAL
    SET "FNAME=%~1"
    SET "DNAME=%~2"

    :: invoke findFile for each line in the file
    FOR /F "tokens=*" %%F IN (%FNAME%) DO (
        CALL :findFile "%DNAME%" "%%~F"
    )


(ENDLOCAL
 EXIT /B 0)



:findFile
SETLOCAL
    SET "DNAME=%~1"
    SET "FNAME=%~2"

    :: Paste the folder to search with the file to find.
    IF NOT EXIST "%DNAME%\%FNAME%" (
        ECHO %FNAME% IS MISSING!!!!
    ) ELSE (
        ECHO found %FNAME%
    )
(ENDLOCAL
 EXIT /B 0)