Ask Your Question

tinku's profile - activity

2020-04-27 08:03:31 -0600 received badge  Popular Question (source)
2019-07-14 12:08:48 -0600 received badge  Notable Question (source)
2018-11-29 22:46:00 -0600 received badge  Popular Question (source)
2018-08-31 16:49:21 -0600 received badge  Student (source)
2016-11-20 15:53:57 -0600 received badge  Editor (source)
2016-11-20 15:49:58 -0600 asked a question OpenCV Out of memory error

I working on a video composition project using multiple user generated videos . Below is my code

df=pd.concat(user,axis=1)
#print df

dfs= df.loc[:, (slice(None), ['Panning','sec'])]


video_index=0
cap=cv2.VideoCapture(videoList[0])

fra=[]
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter("Output.avi", fourcc, fps, (width, height), True)
while(cap.isOpened()):
    ret,frame=cap.read()
    fra.append(frame)

    for index,row in dfs.iterrows():
          if (row[:, 'Panning'] == 'Panning').any():
               idx = row[:, 'Panning'][row[:, 'Panning'] == 'Panning'].index.tolist()
               sec = int(row.loc[(idx, 'sec')].values.tolist()[0])
              if cap.get(0)==1000*sec:
                   cap = cv2.VideoCapture(videoList[indices.index(random.choice(idx))])
                  cap.set(0, sec * 1000)
                  ret, frame = cap.read()
                  fra.append(frame)
          else:

              ret,frame=cap.read()
              fra.append(frame)
              if frame is None:
                  video_index += 1
                  if video_index == len(videoList):
                      break
                  cap = cv2.VideoCapture(videoList[indices.index(long_dur())])

                  cap.set(0,1000*sec)
                  ret, frame = cap.read()
                  fra.append(frame)

When I am trying to run I am getting the following error

  OpenCV Error: Unspecified error (The numpy array of typenum=2, ndims=3 can not be created) in NumpyAllocator::allocate, file ..\..\..\modules\python\src2\cv2.cpp, line 184
OpenCV Error: Insufficient memory (Failed to allocate 6220800 bytes) in cv::OutOfMemoryError, file ..\..\..\modules\core\src\alloc.cpp, line 52
Traceback (most recent call last):
  File "C:/Users/chaitanya/PycharmProjects/Thesis/ROI.py", line 86, in <module>
    ret,frame=cap.read()
cv2.error: ..\..\..\modules\core\src\alloc.cpp:52: error: (-4) Failed to allocate 6220800 bytes in function cv::OutOfMemoryError

I am not able to solve it.need help on this error

2016-11-18 06:37:23 -0600 asked a question Video composition by selecting videos randomly

I have multiple videos that I want to compose to get a single video. Currently I am using the following code to compose a video .

video_index=0
cap=cv2.VideoCapture(video[srt_time[video_index]])
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = cap.get(cv2.CAP_PROP_FPS)
count=cap.get(cv2.CAP_PROP_FRAME_COUNT)
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter("Output.avi", fourcc, fps, (width, height), True)
while(cap.isOpened()):
    ret,frame=cap.read()
    if frame is None:
        print "end of video " + str(video_index) + " .. next one now"
        video_index += 1
        if video_index >= len(videoList):
             break
        cap = cv2.VideoCapture(video[srt_time[video_index]])
        ret, frame = cap.read()
     out.write(frame).

This code gives me a video remix which contains a video one after another. But now I want a video remix which switches views between the videos randomly. Like for example video starts with video 1 and after some time it randomly switches to any of the other two videos . After reading that selected video it again randomly switches to another video. basically, there should be a random switch between videos in the composed videos.

2016-11-04 05:44:41 -0600 commented question Video Stitching of overlapped videos

@StevenPuttemans Thank you for your suggestion I am not aware of that good library than OpenCV which reads frames from a video and writes to a new video. Can you provide me some libraries which can detect the overlap over time and then take switching decisions for composing a video like for the example scenario in the question asked?

2016-11-04 05:39:47 -0600 received badge  Enthusiast
2016-11-03 08:11:11 -0600 commented question Video Stitching of overlapped videos

@Messina Vision Systems I want to swap when there is overlap at a particular time. Like for example video1 is started from 19-13-28 and ends at 19-13-45 and video 2 starts at 19-13-33 and ends at 19-13-59 and video 3 starts at 19-14-05 and ends at 19-14-20. So there is an overlap between video 1 and video 2 at 19-13-33 till 19-13-45. So,I want a final video starting from 19-13-28 to 19-13-45. For doing this i am starting with reading frames from video1 as it is the first video according to the start time. But whenever there is a overlap at 19-33-33 I want to swap with the video with which it is overlapped in this scenario it is video 2 as it starts at 19-13-33.

2016-11-03 06:46:08 -0600 commented question Video Stitching of overlapped videos

@Messina Vision Systems No, video 1 will not have the same frames(in terms of content) as the start of video 2 the view will be different, but at a point of time there may be two videos like in this case video 1 & video2 .So, i wanted to swap between from video 1 to video 2 to get different frames. Once the overlapped duration is completed If they are no frames to be read in video 2 then I will shift to video3 or else I will read the remaining frames left in video 2 and then shift to video 3.

Video content is not to be considered but there should be switching whenever there is an overlap over time but not on time.

2016-11-03 04:30:02 -0600 commented question Video Stitching of overlapped videos

@Messina Vision Systems No I am not after creating a panorama but a video mashup by combining multiple videos.

2016-11-02 11:58:55 -0600 asked a question Video Stitching of overlapped videos

Hello I have multiple videos which overlap at some time and want to stitch these videos to get a single video stream.

for example below are three videos where video 1 and video 2 overlap at some time

enter image description here

Now I wanted the final o/p to be

enter image description here

Where initially video 1 frames are read and written to the video writer object until there is an overlap. Once there is an overlap the view switches from video 1 or video 2 based on some decisions(which is not my question). Once the overlap ends the frames from video 2 are read and written as the video 1 frames are completed. And finally when they are no frames left from video 2, frames from video 3 are read and written.

My question is how to read and write the overlapped videos as i wanted to have the frames from video or video 2 for the overlapped period. The problem I am facing is how to identify the overlap while reading and writing the frames without checking the video content.

I am finding the overlapped time by analyzing the time stamps and also getting the video indices for which there is an overlap. So, how can I use this information to read and write frames for overlapped videos. Below is the on how I am getting the information which will be used for writing

def dict_cam(key,values):
        return {key[i]:values[i] for i in range (len(key))}

 users=dict_cam(indices,intervals) # Creates dictionary with videos indices as keys(indices) with their start and end time as their values(intervals).

 overlapping = [ [i,j,x,y] for i,x in users.iteritems() for j,y in users.iteritems() if x is not y and x[1]>y[0] and x[0]<y[0] ] # For identifying overlapping.


 for x in overlapping

   camera=[x[0]]
   camera.append(x[1])
   begin=x[2][0]
   end=x[2][1]
   begg=x[3][0]
   ens=x[3][1]
   if begin < begg and begg<end:
       overlap.append(begg)
   if ens < end:
       overend.append(ens)
  else:
      overend.append(end)


over_rang=overlap + overend

Where, camera is a list of video indices where there is an overlap, and over_rang is a list which contains the duration of the overlap.

Before starting video writing I am sorting all the video indices with their start time.

I do not want to analyze the video content rather use the information about the overlapped time and the indices where there is a overlap.

2016-10-05 11:16:20 -0600 asked a question Video composition by switching between multiple cameras

I wanted to compose a video from multiple cameras. While stitching I wanted to switch view from one camera to another. Is it possible to do it in OpenCv?

For example I have 3 video paths(videos having same duration) and wanted to create a single video summary by switching between the videos. To start with I have created 3 video capture objects as shown below.

cap0=cv2.VideoCapture(path1)
cap1=cv2.VideoCapture(path2)
cap2=cv2.VideoCapture(path3)

similary, I also created

ret,frame0=cap0.read()
ret,frame1=cap1.read()
ret,frame3=cap2.read()

Now initially I will have frames from that are read by cap0 and passed into VideoWriter object. After some time I wanted to insert frames that are read from path2 from the time where I switched from path 1. like If I wrote frames till 3 sec from path 1,I wanted to insert frames of path 2 from the 4 sec till 6 sec

Now if I switch back again to path1 then I wanted to insert frames from the 7 sec by skipping the frames of path1 from 4sec to 6 sec.

Is there any way doing this like may be skipping the frames or any other alternative

2016-09-26 05:25:14 -0600 asked a question How to create multiple VideoCapture Obejcts

I wanted to create multiple VideoCapture Objects for stitching video from multiple cameras to a single video mashup.

for example: I have path for three videos that I wanted to be read using Video Capture object shown below to get the frames from individual videos,so they can be used for writing.

Expected:For N number of video paths

   cap0=cv2.VideoCapture(path1)
   cap1=cv2.VideoCapture(path2)
   cap2=cv2.VideoCapture(path3)
   .
   . 
   capn=cv2.VideoCapture(path4)

similarly I also wanted to create frame objects to read frames like

ret,frame0=cap0.read()
ret,frame1=cap1.read()
.
.
ret,frameN=capn.read()

I tried using for loop on the lists where the paths are stored but every time only one path is read and frames are stored for that particular video only.I have seen in many forums it is possible to create multiple capture objects in C++ but not in python in dynamic scenario where number of videos are not known before hand.

videoList=glob.glob(r'C:\Users\chaitanya\Desktop\Thesis\*.avi')
        frames=[]
            for path in videoList:
                indices=[]
                cap = cv2.VideoCapture(path)
                while(cap.isOpened()):
                    ret,frame=cap.read()
                    if not ret:
                        break
                    indices.append(cap.get(1))
                frames.append(indices)
    cap.release()
    cv2.destroyAllWindows()