Ask Your Question

mikey's profile - activity

2014-09-17 10:14:18 -0600 asked a question VideoCapture from socket makefile() call?

Hi,

I am streaming video over a network through sockets. I am able to view the video with mplayer so I know it arrives correctly. What I would like to do is capture that video stream over the socket with cv2.VideoCapture. I have tried as shown below but it gives a TypeError (also shown below). Is there a way to capture this video through VideoCapture or some other opencv functionality?

My Capture code:

import socket
import cv2
import struct
import io
import numpy as np
import traceback

def main():
    try:
        server_socket = socket.socket()
        server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        server_socket.bind(('0.0.0.0', 5001))
        server_socket.listen(0)
        connection = server_socket.accept()[0].makefile('rb')

        cv2.namedWindow("test-h264", cv2.WINDOW_NORMAL)
        video = cv2.VideoCapture(connection)
        while True:
            ret,frame = video.read()           
            cv2.imshow("test-h264",frame)
    except Exception as e:
        traceback.print_exc()
    finally:
        connection.close()
        server_socket.close()

if __name__ == "__main__":
    main()

The error message:

camera$ python testh264.py 
<socket._fileobject object at 0x2b07cd0>
init done 
opengl support available 
Traceback (most recent call last):
  File "testh264.py", line 23, in main
    video = cv2.VideoCapture(connection)
TypeError: an integer is required
camera$

The video stream is from a picamera, is 1080p and is in h.264 format. The code above is on a laptop with ubuntu 12.04 installed.

Any suggestions would be appreciated.

Thanks...

Mike

2014-07-13 10:23:23 -0600 commented answer aligning two cameras with similar views

Thanks Witek, I will take a look. The images are blurred due to the motion, of which I have not figured out a solution to that yet. And the reflection I saw after the fact and am rearranging the gear I use to remove the reflections. As for the view, this is one of the reasons for the data collect as understanding roads where there's not much there to go with is one of the problems that needs to be addressed over the next few years. Again thanks...

2014-07-09 16:21:39 -0600 asked a question aligning two cameras with similar views

Hi

I have a pair of cameras (picameras) setup in my vehicle at the top of the windshield looking out the front. They are about 22" apart. I capture an image stream from each one and view them side-by-side using OpenCV. Are there OpenCV tools to align the two cameras? I believe this would be akin to having the two views registered to each other? I have started a blog discussing this project which gives more detail: http://auvrnh.blogspot.com/ where there are some sample images taken from the captured image streams.

Thanks...

2014-06-21 13:02:03 -0600 received badge  Student (source)
2014-06-21 07:55:18 -0600 asked a question saving image streams from multiple cameras

Hi

I have multiple pi cameras sending image streams to an opencv app (one threaded app that receives all streams). I would like to save each stream independently with unique name for each one. I have the gps and utc data associated with each one, so I was considering maybe appending left, right, etc to each stream. After the data is saved, I will create an app to load them, either separately or together and view them side-by-side and/or to perform analysis on them. I'm not sure if they should all be saved in the same directory or if each stream gets their own directory, etc. Any advice would be appreciated.

Thanks...

2014-06-21 07:16:44 -0600 asked a question circular buffer for image stream

Hi

I have a pi camera generating an image stream and would like to save a certain amount of images that have already been generated, hence I believe a circular buffer would do the trick. Is there an opencv python solution for this?

Thanks...

2014-06-06 20:41:20 -0600 asked a question Viewing multiple image streams at same time using python

Are there examples showing how to view multiple image streams at the same time? I have two cameras (pi's) that each send an image stream back to my pc. I can view each one individually but have not been able to get them to display well at same time. I am doing this in two separate threads at the moment with each using a namedWindow (each window has different name). One of them is small and the other is correct size. I am using the python api. I do get the following error/warning messages when attempting this.

QObject::moveToThread: Widgets cannot be moved to a new thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QMetaMethod::invoke: Unable to invoke methods with return values in queued connections
eQMetaMethod::invoke: Unable to invoke methods with return values in queued connections

Any suggestions would be appreciated.

Thanks...

2014-04-27 15:23:51 -0600 asked a question Python Canny output image is smaller than input image

Hi

In running the Canny function I've noticed that the output from Canny is smaller than the original input image.

imgnp = numpy.array(original_image)
imgcv = imgnp[:, :, ::-1].copy()
gray = cv2.cvtColor(imgcv, cv2.COLOR_BGR2GRAY)
edges = cv2.GaussianBlur(gray, (3,3), 0)
edges = cv2.Canny(edges,75,200,apertureSize=3, L2gradient=True)
print('imgcv size: %d\n' % imgcv.size)
print('edges size: %d\n' % edges.size)

The print out is:

imgcv size: 6220800

edges size: 2073600

Why is the output from the Canny function smaller than the input. I'd like to add the detected edges to original image for viewing and it seems like that would be easier if both were the same size

Thanks...

edit 1: I think I've figured out why. When using the the image's shape field, it returns imgcv shape = (1080, 1920, 3) edges shape = (1080, 1920)

The image used to find edges from has three dimensions, I'm thinking they are for RGB (or BGR).

2014-04-26 09:41:19 -0600 asked a question Overlaying edges onto original image in Python

Hi

I would like to overlay an image with the edges detected by the Canny function (or from any other function) using the Python API. Any suggestions would be appreciated.

Thanks...

edit 1: In figuring out a different question I think I've figured out some relevant information. When using the the image's shape field, it returns imgcv shape = (1080, 1920, 3) edges shape = (1080, 1920)

The image used to find edges from has three dimensions, I'm thinking they are for RGB (or BGR). So I'm thinking, to combine the two images, only one of the dimensions in the original image needs to be accessed, although I'm still not clear as to how this is done.

2014-04-24 12:20:38 -0600 received badge  Editor (source)
2014-04-24 12:04:50 -0600 asked a question read streaming video from network camera in OpenCV Python

Hi

I am streaming video and images from a network camera (raspberry pi camera) to my ubutnu laptop. I would like to capture it on my ubuntu 12.04 laptop using OpenCV. Is there an example in python code to do this? I have done a proof of concept to make sure the video was arriving at the laptop through the use of netcat and mplayer.

Thanks...

edit: Some more info: the video is sent over a socket, so I would like to capture video stream coming through a socket on the laptop.

edit ii: It looks like I sending an image sequence from the pi camera to the laptop but opencv doesn't seem to want to display the image sequence (using imshow). Id be glad to enter the code I'm using if you'd think that would help

edit iii: I figured out a bit of it. I needed a cv2.waitKey(1) after my cv2.imshow.