Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 322

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

$
0
0
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: NO FFMPEG: YES avcodec: YES (ver 56.1.0) avformat: YES (ver 56.1.0) avutil: YES (ver 54.3.0) swscale: YES (ver 3.0.0) avresample: YES (ver 2.1.0) GStreamer: NO OpenNI: NO OpenNI PrimeSensor Modules: NO OpenNI2: NO PvAPI: NO GigEVisionSDK: NO Aravis SDK: NO UniCap: NO UniCap ucil: NO V4L/V4L2: NO/YES XIMEA: NO Xine: NO gPhoto2: NO Parallel framework: pthreads Other third-party libraries: Use IPP: NO Use VA: NO Use Intel VA-API/OpenCL: NO Use Lapack: NO Use Eigen: NO Use Cuda: NO Use OpenCL: YES Use OpenVX: NO Use custom HAL: YES (carotene (ver 0.0.1)) OpenCL: Include path: /home/pi/opencv-3.2.0/3rdparty/include/opencl/1.2 Use AMDFFT: NO Use AMDBLAS: NO Python 2: Interpreter: /home/pi/.virtualenvs/cv/bin/python2.7 (ver 2.7.9) Libraries: /usr/lib/arm-linux-gnueabihf/libpython2.7.so (ver 2.7.9) numpy: /home/pi/.virtualenvs/cv/local/lib/python2.7/site-packages/numpy/core/include (ver 1.12.1) packages path: lib/python2.7/site-packages Python 3: Interpreter: /usr/bin/python3.4 (ver 3.4.2) Libraries: /usr/lib/arm-linux-gnueabihf/libpython3.4m.so (ver 3.4.2) numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.8.2) packages path: lib/python3.4/site-packages Python (for build): /home/pi/.virtualenvs/cv/bin/python2.7 Java: ant: NO JNI: NO Java wrappers: NO Java tests: NO Matlab: Matlab not found or implicitly disabled Documentation: Doxygen: NO Tests and samples: Tests: YES Performance tests: YES C/C++ Examples: YES Install path: /usr/local cvconfig.h is in: /home/pi/opencv-3.2.0/build the error being returned is: python writing_video.py --output example.avi [INFO] warming up camera... Traceback (most recent call last): File "writing_video.py", line 38, in frame = imutils.resize(frame, width=300) File "/home/pi/.virtualenvs/cv/local/lib/python2.7/site-packages/imutils/convenience.py", line 69, in resize (h, w) = image.shape[:2] AttributeError: 'NoneType' object has no attribute 'shape ^ I've gone into the covenience.py to see if i could spot any mistakes I'm making but it seemed to line up with my code I understand that Nonetype error means that there is no value in shape, Ihence why it cant be called. 've been stuck on this error for over a week now no answer in sight. I've just re-imaged my pi and re-installed opencv-3.2.0 for python2.7. I've been working through the NoneType resolution article (http: //www.pyimagesearch.com/2016/12/26/opencv-resolving-nonetype-errors/) From this I've concluded that the camera is full functional, i'm able to take raspstill and record a video. But I'm unable to play a video through omxplayer. when played the details and have a nice day ;) are shown but no new window opens up. My assumptions are that its a codec or driver issue, also Adrian left a comment that opencv was likely compliled without video I/O support. After hours of searching and troubleshooting i'm still unsure how to resolve this error. Any help would be greatly appreciated! thanks

Viewing all articles
Browse latest Browse all 322

Trending Articles