Unexpected shut down on Opencv

asked 2016-04-16 10:12:05 -0600

updated 2016-04-16 10:54:58 -0600

berak gravatar image

Hello there, Im a beginner in Python even in Opencv, but somehow ive reached the code below. Im 3 weeks with a desperate trouble: The recognition console shut down and write the .txt before the video ends, and have no idea why. I would appreciate any tip regardin this problem, Previous thanks.

  import sys
import argparse
import datetime
import time
import cv2
import numpy as np
import copy
import glob, os, sys
##import xlwt
##from xlwt import easyxf
##from xlwt import Workbook
##from xlwt import *



video_input =""       #initializing string variable for raw data input
video_input = raw_input("Enter the name of your text file - please use / backslash when typing in directory path: ")



filename= os.path.join(video_input)
filename_1= os.path.basename(filename)
directory_name = os.path.dirname(os.path.realpath(video_input))
print directory_name

filename_2= os.path.splitext(video_input)[0]
#date_time=time.ctime(os.path.getctime(filename))
#print date_time

cap = cv2.VideoCapture(filename)
#prepare to extract background
fgbg = cv2.BackgroundSubtractorMOG(150,16,False)
#kernel for dilation
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))

framecount = cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)
print framecount

# Take first frame and make it grey. Will use for searching the template
ret, frame1= cap.read()

rows= frame1.shape[0]
cols= frame1.shape[1]
a=((rows/2)-30)
b=a+100
c=b+99
d=(cols/10)+4
gray1 = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY)
# Create a mask image for drawing purposes
mask_zeros = np.zeros_like(frame1)

#drawing the coordinates grid
cv2.line(mask_zeros,(0,a),(cols,a),(1,238,251),1)
cv2.line(mask_zeros,(0,b),(cols,b),(1,238,251),1)
cv2.line(mask_zeros,(0,c),(cols,c),(1,238,251),1)
cv2.line(mask_zeros,(d,a),(d,rows),(1,238,251),1)
cv2.line(mask_zeros,(d*2,a),(d*2,rows),(1,238,251),1)
cv2.line(mask_zeros,(d*3,a),(d*3,rows),(1,238,251),1)
cv2.line(mask_zeros,(d*4,a),(d*4,rows),(1,238,251),1)
cv2.line(mask_zeros,(d*5,a),(d*5,rows),(1,238,251),1)
cv2.line(mask_zeros,(d*6,a),(d*6,rows),(1,238,251),1)
cv2.line(mask_zeros,(d*7,a),(d*7,rows),(1,238,251),1)
cv2.line(mask_zeros,(d*8,a),(d*8,rows),(1,238,251),1)
cv2.line(mask_zeros,(d*9,a),(d*9,rows),(1,238,251),1)

#putting the text for coordinates grid
font = cv2.FONT_HERSHEY_SIMPLEX
#for X
cv2.putText(mask_zeros,"0",(0,a),font, 0.5,(1,238,251),1,cv2.CV_AA)
cv2.putText(mask_zeros,"100",(d,a),font, 0.5,(1,238,251),1,cv2.CV_AA)
cv2.putText(mask_zeros,"200",(d*2,a),font, 0.5,(1,238,251),1,cv2.CV_AA)
cv2.putText(mask_zeros,"300",(d*3,a),font, 0.5,(1,238,251),1,cv2.CV_AA)
cv2.putText(mask_zeros,"400",(d*4,a),font, 0.5,(1,238,251),1,cv2.CV_AA)
cv2.putText(mask_zeros,"500",(d*5,a),font, 0.5,(1,238,251),1,cv2.CV_AA)
cv2.putText(mask_zeros,"600",(d*6,a),font, 0.5 ...
(more)
edit retag flag offensive close merge delete