Ask Your Question

aj_nikhil's profile - activity

2020-10-27 16:05:44 -0600 received badge  Notable Question (source)
2019-06-07 08:38:32 -0600 received badge  Popular Question (source)
2018-11-29 23:32:27 -0600 received badge  Popular Question (source)
2017-03-06 21:10:26 -0600 received badge  Famous Question (source)
2016-07-05 08:53:43 -0600 received badge  Notable Question (source)
2016-04-05 06:04:28 -0600 received badge  Popular Question (source)
2015-02-24 00:50:43 -0600 asked a question Reading Frames of uncompressed yuv video file?

I recorded an uncompressed / un-encoded video in yuv format using camera of my raspberry pi. I want to read each frame as an image and also count the total number of frames of the video, using OpenCV.

I found this answer, but it looks old and doesn't seem to work. Do I have to convert yuv video to some other format first to read each frame. How should I go about it?

2015-02-16 03:18:35 -0600 received badge  Enthusiast
2015-02-13 06:02:41 -0600 commented answer Counting the Total number of Frames in a video file ?

So .h264 video that I have is NAL stream and doesn't have the information that's why maybe OpenCv is not able to return it. One method is to wrap .h264 in a container like .mp4 and then count the number of frames of the wrapped video. get(7) returns the total frame in that case. I verified both ways to calculate the total number of frames. Both match.

2015-02-13 05:59:26 -0600 received badge  Scholar (source)
2015-02-13 05:59:23 -0600 received badge  Supporter (source)
2015-02-13 02:18:39 -0600 received badge  Student (source)
2015-02-13 00:48:27 -0600 asked a question Counting the Total number of Frames in a video file ?

I am trying to count total number of Frames in my video file ('foo.h264').

>>> import numpy as nm
>>> import cv2
>>> cap = cv2.VideoCapture('foo.h264')
>>> cap.get(CV_CAP_PROP_FRAME_COUNT)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'CV_CAP_PROP_FRAME_COUNT' is not defined
>>> cap.get(5)
25.0
>>> cap.get(7)
-192153584101141.0

So I think get(5) is giving frame rate and get(7) gives total number of frames. Obviously get(7) is incorrect in the above case. So I tried to find these values in an .avi file.

>>> cap = cv2.VideoCapture('foo.avi')
>>> cap.get(5)
29.97002997002997
>>> cap.get(7)
256379.0

I can calculate the total number of frames by multiplying FPS by duration of the video, but I'm not sure if the FPS given for .h264 is right or not. Why does it give negative number of total frames? Is this a bug?
P.S: I recorded this video file(.h264) using raspberry pi camera.

2015-02-12 06:43:37 -0600 received badge  Editor (source)
2015-02-12 06:42:49 -0600 asked a question Not able to play h264 video on OpenCV?

I captured a standard video from camera of Raspberry pi. The codec of the file is h264. To play the video I do:

import numpy as np
import cv2

cap = cv2.VideoCapture('foo.h264')

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

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

Video starts But stops after sometime throwing this error:

Traceback (most recent call last):
  File "play_video.py", line 9, in <module>
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: /home/nikhil/Downloads/opencv-2.4/modules/imgproc/src/color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cvtColor

My machine has Ubuntu 12.04. I played an .avi file it plays smoothly. Is the problem with the .h264 or with the OpenCV?

2015-02-11 07:19:06 -0600 asked a question Not able to install OpenCV?

Installation steps I followed

  1. Downloaded the 2.4.10 version of OpenCV (zip file) from the official website.
  2. Unzipped the file
  3. Installed all the dependencies for OpenCV

    sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev

  4. Then used these commands

    mkdir build cd build cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

It starts building. After the build when I give the make command the following error comes

/home/nikhil/Downloads/opencv-
2.4.10/modules/core/src/system.cpp:280:10: error: inconsistent operand constraints in an ‘asm’
make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o] Error 1
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make: *** [all] Error 2

My OS is Ubuntu 12.04

Please can anyone suggest me what wrong I am doing here. Been stuck on this since 2 days. TIA.