NoneType attribute error, no object shape & omxplayer unable to play video

asked 2017-03-31 11:36:16 -0500

Sinjon gravatar image

updated 2017-04-03 08:49:44 -0500

Hello,

I'm trying to get the following working

# import the necessary packages
from __future__ import print_function
from imutils.video import VideoStream
import numpy as np
import argparse
import imutils
import time
import cv2

# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-o", "--output", required=True,
    help="path to output video file")
ap.add_argument("-p", "--picamera", type=int, default=-1,
    help="whether or not the Raspberry Pi camera should be used")
ap.add_argument("-f", "--fps", type=int, default=20,
    help="FPS of output video")
ap.add_argument("-c", "--codec", type=str, default="MJPG",
    help="codec of output video")
args = vars(ap.parse_args())

# initialize the video stream and allow the camera
# sensor to warmup
print("[INFO] warming up camera...")
vs = VideoStream(usePiCamera=args["picamera"] > 0).start()
time.sleep(2.0)

# initialize the FourCC, video writer, dimensions of the frame, and
# zeros array
fourcc = cv2.VideoWriter_fourcc(*args["codec"])
writer = None
(h, w) = (None, None)
zeros = None
# loop over frames from the video stream
while True:
    # grab the frame from the video stream and resize it to have a
    # maximum width of 300 pixels
    frame = vs.read()
    frame = imutils.resize(frame, width=300)

    # check if the writer is None
if writer is None:
    # store the image dimensions, initialzie the video writer,
    # and construct the zeros array
    (h, w) = frame.shape[:2]
    writer = cv2.VideoWriter(args["output"], fourcc, args["fps"],
    (w * 2, h * 2), True)
    zeros = np.zeros((h, w), dtype="uint8")
    # break the image into its RGB components, then construct the
    # RGB representation of each frame individually
    (B, G, R) = cv2.split(frame)
    R = cv2.merge([zeros, zeros, R])
    G = cv2.merge([zeros, G, zeros])
    B = cv2.merge([B, zeros, zeros])

# construct the final output frame, storing the original frame
# at the top-left, the red channel in the top-right, the green
# channel in the bottom-right, and the blue channel in the
# bottom-left
    output = np.zeros((h * 2, w * 2, 3), dtype="uint8")
    output[0:h, 0:w] = frame
    output[0:h, w:w * 2] = R
    output[h:h * 2, w:w * 2] = G
    output[h:h * 2, 0:w] = B

# write the output frame to file
    writer.write(output)
# show the frames
    cv2.imshow("Frame", frame)
    cv2.imshow("Output", output)
    key = cv2.waitKey(1) & 0xFF

# if the `q` key was pressed, break from the loop
if key == ord("q"):
    sys.exit()

# do a bit of cleanup
    print("[INFO] cleaning up...")
    cv2.destroyAllWindows()
    vs.stop()
    writer.release()

Build Information:

UI: 
    QT:                          NO
    GTK+ 2.x:                    YES (ver 2.24.25)
    GThread :                    YES (ver 2.42.1)
    GtkGlExt:                    NO
    OpenGL support:              NO
    VTK support:                 NO

  Media I/O: 
    ZLib:                        /usr/lib/arm-linux-gnueabihf/libz.so (ver 1.2.😎
    JPEG:                        libjpeg (ver 90)
    WEBP:                        build (ver 0.3.1)
    PNG:                         /usr/lib/arm-linux-gnueabihf/libpng.so (ver 1.2.50)
    TIFF:                        build (ver 42 - 4.0.2)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)
    GDAL:                        NO
    GDCM:                        NO

  Video I/O:
    DC1394 1.x:                  NO
    DC1394 2.x ...
(more)
edit retag flag offensive close merge delete

Comments

  • can you try again with the code, please ?
  • "... and re-installed opencv-3.2.0 for python2.7. " -- what did you do, exactly ?
  • look at cv2.getBuildInformation() , to see, what kind of video support was compiled in
  • cv2.__version__ returns what ?
berak gravatar imageberak ( 2017-03-31 12:11:02 -0500 )edit

ah, sorry, print cv2.getBuildInformation()

berak gravatar imageberak ( 2017-03-31 13:09:34 -0500 )edit
1

I'm trying to output the build information as its shown in terminal but I'm not sure how to stop it from grouping?

Sinjon gravatar imageSinjon ( 2017-03-31 13:43:13 -0500 )edit

delete latest attempt, try again, with the 10101 button (code formatting), not the " one (cite)

berak gravatar imageberak ( 2017-03-31 13:51:40 -0500 )edit

Any idea derak?

Sinjon gravatar imageSinjon ( 2017-04-02 05:03:08 -0500 )edit