错误:(-215)size.width> 0&&函数imshow中的size.height> 0

时间:2015-08-11 12:47:18

标签: python opencv

程序需要读取视频,进行帧计数,然后在窗口中显示。视频结束后发生错误。 我该如何解决这个问题?

以下是来源:

<?php

 require('connection/connection.php');

 if(isset($_POST['submit'])) {
    $firstname = $_POST['firstname'];
    $lastname =$_POST['lastname'];
    $email = $_POST['email'];
    $tel = $_POST['tel'];
    $password = $_POST['pass'];
    $flat =$_POST['flat'];
    $num =$_POST['num'];
    $street =$_POST['street'];
    $district =$_POST['district'];
    $selected_val = $_POST['city'];

    mysql_query('SET NAMES utf8');

    //form validation.
    if(empty($_POST['firstname'])){

        echo "qq";
    } else{
        $query = "INSERT INTO `parenuser` 
                    (flat, num, street, district, 
                     city, firstname, lastname, tel, 
                     pass, email) 
                  VALUES 
                    ('$flat', '$num', '$street', '$district', 
                     '$selected_val', '$firstname', '$lastname', '$tel', 
                     '$password', '$email')";


        $result = mysql_query($query);

        if($result){

            header("Location: success.html");

        }

    }

}
?>

完成错误:

import tkMessageBox
import cv2

banner = cv2.imread('../data/banner.png')
video = cv2.VideoCapture('../data/pintado_real_crop.avi')
contadorDeFrames = True
contador = 0


cv2.imshow('Projeto Pacu', banner)

cv2.moveWindow('Projeto Pacu', 100,50)

while(contadorDeFrames == True):

    contadorDeFrames, frame = video.read()
    contador = contador + 1

    cv2.imshow("Video", frame)
    cv2.moveWindow('Video', 100, 178)

    print"Frame: %d" %contador

    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break

tkMessageBox.showinfo("Frames contador: %d" %contador)
video.release()
cv2.destroyAllWindows()

2 个答案:

答案 0 :(得分:0)

在您的代码中,您正在尝试打印空框架:

$Cxml = '<Conds><C><FieldNo>119</FieldNo><Filter>' . $variable . '</Filter></C></Conds>';

当您的代码读取最后一帧+ 1的帧时,该值将为null并且您正在尝试打印该帧。因此,检查框架是否为空并打印。

答案 1 :(得分:0)

我没有问题的答案,但我可以指出错误来自哪里,我有一个解决方法。

就像你在我的第一个例子中看到的那样,我试图在if语句中打印退出并注意到它没有被调用。所以我展示了视频有多少帧,让if语句被framenumbers调用。所以错误消失。

示例1:

   import numpy as np
   import cv2

    cap = cv2.VideoCapture('richtigcounter.mp4')
    frames =1
    while True:
    ret, frame = cap.read()
    print ("test")
    cv2.imshow('frame',frame)
    frames =frames + 1
    print (frames)
if cv2.waitKey(1) & 0xFF == ord('q'):
print("Quit")
break

cap.release()
cv2.destroyWindow(cap)

示例2:

    import numpy as np
    import cv2
    import time

    def Reinfall():
        cap = cv2.VideoCapture('reinfallcounter.mp4')
        frames =1

        while True:
        ret, frame = cap.read()




        cv2.imshow('video', frame)
        frames =frames + 1
        print (frames)
        cv2.waitKey(1)
        if frames == 245:
          print("Quit")
          break

cap.release()
cv2.destroyAllWindows()