6

Context:

I have been playing around with python's wrapper for opencv2. I wanted to play with a few ideas and use a wide angle camera similar to 'rear view' cameras in cars. I got one from a scrapped crash car (its got 4 wires) I took an educated guess from the wires color codding, connect it up so that I power the power and ground line from a usb type A and feed the NTSC composite+ composite- from an RCA connector. I bought a NTSC to usb converter like this one.

It came with drivers and some off the shelf VHStoDVD software.

the problem:

I used the run of the mill examples online to trial test it like this:

import numpy as np
import cv2

cam_index=0
cap=cv2.VideoCapture(cam_index)


print cap.isOpened()
ret, frame=cap.read()

#print frame.shape[0]
#print frame.shape[1]

while (cap.isOpened()):
    ret, frame=cap.read()
    #gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)


    cv2.imshow('frame', frame)


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

#release and close 
cap.release()
cv2.destroyAllWindows() 

this is the output from shell:

True

Traceback (most recent call last):
  File "C:/../cam_capture_.py", line 19, in <module>
    cv2.imshow('frame', frame)
error: ..\..\..\..\opencv\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0 in function cv::imshow

>>> 

key Observations:

SCREENSHOTS

  1. in control panel the usb dongle is shown as 'OEM capture' in Sound Video & Game controllers . So it's not seen as a simple plug and play Webcam in 'Imaging devices'

  2. If I open the VHStoDVD software I need to configure 2 aspects:

    • set as Composite
    • set enconding as NTSC then the camera feed from the analog camera is shown OK within the VHStoDVD application
  3. When I open the device video channel in FLV (device capture). The device stream is just a black screen but IF i open the VHStoDVD software WHILE flv is streaming I get the camera's feed to stream on FLV and a black screen is shown on the VHStoDVD feed. Another important difference is that there is huge latency of aprox 0.5sec when the feed is in FLV as opposed to running in VHStoDVD.

  4. When running "cam_capture.py" as per the sample code above at some put during runtime i will eventually get a stop error code 0x0000008e:

detail:

stop: 0x0000008E (0xC0000005, 0xB8B5F417, 0X9DC979F4, 0X00000000 )

ks.sys - Address B8B5F417 base at B8B5900, Datestamp...

beg mem dump
phy mem dump complete

5.if i try to print frame.shape[0] or frame.shape[1] I get a type error say I cannot print type None

6.if try other cam_index the result is always false

TLDR:

In 'control panel' the camera device is under 'sound video & game controllers' not under 'imaging devices';

The cam_index==zero;

The capture.isOpened()=True;

The frame size is None;

If VHStoDVD is running with composite NTSC configured the camera works , obviously you cant see the image with printscreen in attachment but trust me ! ;)

Is there any form of initialisation of the start of communication with the dongle that could fix this i.e. emulate VHStoDVD settings (composite+NTSC)? I thought I could buspirate the start of comms between VHStoDVD and the dongle but it feels like I am going above and beyond to do something I thought was a key turn solution.

Any constructive insights, suggestion , corrections are most welcome!

Thanks

Cheers

user3380927
  • 232
  • 2
  • 8
  • for reference: xp 2002 sp3 i5 @2.67GHz 2GB RAM 200GB – user3380927 Mar 03 '14 at 13:06
  • This question is very similar to initial threads from "user3285283" but his problem was never "solved" as such. – user3380927 Mar 03 '14 at 15:18
  • Just trying to understand the problem - how can you get the `stop:...` error and also the standard traceback error? It seems like you would get the traceback immediately and it wouldn't 'run'..? – KobeJohn Mar 03 '14 at 15:37
  • This might be a lot of troubleshooting. Please use [this chat](http://chat.stackoverflow.com/rooms/48888/opencv-videocapture-from-non-standard-usb-video) if you don't mind. – KobeJohn Mar 03 '14 at 15:43
  • apparently I don't have enough rep to use chat but here goes: – user3380927 Mar 03 '14 at 15:49
  • first time run "Traceback " error – user3380927 Mar 03 '14 at 15:50
  • second time run stop error – user3380927 Mar 03 '14 at 15:50
  • running with FLV only just a black screen – user3380927 Mar 03 '14 at 15:51
  • running with FLV while VHStoDVD is initialised I get the camera feed to show on FLV but the feed on VHStoDVD goes black – user3380927 Mar 03 '14 at 15:52
  • if I repeat the same behaviour with py , i.e. if i run VHStoDVD and then run py ; the VHStoDVD goes black but py 'frame' is just a green screen (0,136,0) – user3380927 Mar 03 '14 at 15:53
  • the software that is able to open the video channel in this case "VHStoDVD 2.0 SE" it seems like a very old version of these [link from the manufacturer](http://www.honestech.com/main/Video_Graphics.asp) – user3380927 Mar 03 '14 at 16:10
  • the hardware is Logilink's "VG0001A USB2.0 Video Grabber with Audio" it is possibly discontinued (it was cheap) [link to the closest product from the manufacter] (http://www.logilink.eu/showproduct/VG0005B.htm) – user3380927 Mar 03 '14 at 16:17
  • actual spec from [link](http://www.conrad.com/ce/en/product/956297/Logilink-Usb-20-VideoAudio-Grabber) : USB 2.0/1.1 specification NTSC: 720×480 / 30fps PAL: 720×576 / 25fps – user3380927 Mar 03 '14 at 16:18
  • @kobejohn you are our only hope https://xkcd.com/979/ – user3380927 Mar 03 '14 at 16:44
  • Sorry I don't have time to work on this more today. Please try with a regular webcam to make sure it works. Then investigate more about the frame object you have as I wrote in chat. Then make sure to try many device ids to see if maybe it's just available under a different device id than you expected. Good luck. Hopefully the flag I raised will get a mod to give you access to write in the chat room. – KobeJohn Mar 03 '14 at 17:28
  • When using normal webcam (Creative Live! Cam Chat HD) there is no issue, condition is OK. I will try to investigate deeper in the characterics of 'frame' when using the analog camera. I will also try permutations of the function - cap.set(,value) If have any breakthroughs I will report or maybe more easily close this and open separate ticket. どうもありがとうございます 頑張ります – user3380927 Mar 04 '14 at 09:00

3 Answers3

7

Ok , so after deeper investigation the initial suspicion was confirmed i.e. because the NTSC dongle is not handled as an imaging device (it's seen as a Video Controller , so similar to an emulation of a TV Tuner card ) it means that although we are able to call cv2.VideoCapture with cam_index=0 the video channel itself is not transmitting because we are required to define a bunch of parameters

  1. encoding
  2. frame size
  3. fps rate etc

The problem is because the device is not supported as an imaging device calling cv2.VideoCapture.set(parameter, value) doesn't seem to change anything on the original video feed.

I didn't find a solution but I found a work around. There seems to be quite a few options online. Search for keywords DV to webcam or camcorder as a webcam.

I used DVdriver (http://www.trackerpod.com/TCamWeb/download.htm) (i used the trial because I am cheap!).

Why does it work?

As much as I can tell DVdriver receives the data from the device which is set as a Video controller (similar to a capture from "Windows Movie Maker" or ffmpeg) and then through "fairydust" outputs the frames on cam_index=0 (assumed no other cam connected) as an 'imaging device' webcam.

Summary

TLDR use DVdriver or similar.

I found a workaround but I would really like to understand it from first principles and possible generate a similar initialisation of the NTSC dongle from within python, without any other software dependencies but until then, hopefully this will help others who were also struggling or assuming it was a hardware issue.

I will now leave you with some Beckett: Ever tried. Ever failed. No matter. Try again. Fail again. Fail better. (!)

Community
  • 1
  • 1
user3380927
  • 232
  • 2
  • 8
  • Congratulations on finding the workaround. You also confirmed that it is actually picking up on the camera with the original setup so that is a big step. You mentioned that `cv2.VideoCapture.set(...)` didn't work but let me make sure... when you use that I am pretty sure you have to call it on the instance of VideoCapture that you created. I.e. `cap = cv2.VideoCapture(..)` followed by `cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 1024)`. Were you doing that already? – KobeJohn Mar 04 '14 at 23:03
  • I used "import cv2.cv as cv" just for less verbose but same implementation. previous scenario was 1) VHStoDVD software capture Camera as standalone application result: video feed was OK 2) While VHStoDVD is in capture mode run the py script simultaneously result: the py script 'frame' was a green screen BGR (0,136,0) and VHStoDVD feed becomes a black screen; 3) running script as standlone no additional capture software result: stop error code 0x00000008 – user3380927 Mar 04 '14 at 23:45
  • now in scenario 2 (green screen) I interrogated the frame.shape is 720x576 when forcing new height or width with cv.set() then the result is always 720x576. This ratio is PAL which I assume is probably the DONGLE default 'configuration'. – user3380927 Mar 04 '14 at 23:52
  • So I tried changing CV_CAP_PROP_MODE->2 (mode_640x480_YUV422) meaning to force it to NTSC decoding. result: the display is still a green screen with 720x576. I think the fundamental problem is that there will probably be some initialisation which cannot be achieved within OPENCV framework as it can only handle 'imaging devices' so an additional ad-hoc driver would be needed which seem to be what DVdriver is able to do in the background. – user3380927 Mar 04 '14 at 23:53
  • @kobejohn Do you think it would be possible to achieve the same functionality of DVdriver without using third party software just within python? i.e. initialise video feed for capture device and parse an 'image device' pseudo webcam feed for opencv framework to use? – user3380927 Mar 05 '14 at 00:13
  • I'm sure it's possible but you may have to modify OpenCV as in some blogs I have read. If you or I were already an expert, I bet we could figure it out (look at the converter chip / device information). Or if we had real documentation from the converter then maybe we could figure it out. But we are not experts and have no documentation! Sorry I couldn't help with this. – KobeJohn Mar 05 '14 at 00:34
  • No need for sorry! thank you for your help! The important thing is to always be improving! またいつか会いましょう。 – user3380927 Mar 05 '14 at 08:56
1

It's a few months late, but might be useful. I was working on a Windows computer and had installed the drivers that came with the device, I tried the same code as your question with an Ezcap from Somagic and got the same error. Since "frame is None," I decided to try an if statement around it - in case it was an initialization error. Placing into the loop:

if frame is None:
    print 0
else:
    print 1

The result is: 01110111111111111111111111111...

And if the frame = cap.read(), above the loop is commented out - I get: 00111111111111111...

So for my device capture device it appears to be working for all frames beyond the 5th are captured. I'm not sure why this is, but it might be a useful work around for now.

Disclaimer: Unfortunately, my camera input is currently in a radiation field so I can't get to it for a couple of weeks to make sure it works for sure. However, the images are currently a black frame (which is expected without proper input).

joelk
  • 11
  • 2
1

I faced the same issue. As a workaround, I first tried the solution proposed by @user3380927 and it worked indeed. But since I didn't want to rely on an external software, I started tweaking parameters using opencv in Python.

This lines of code worked like a charm (you have to insert them before reading the frame for the first time):

cam.set(cv2.CAP_FFMPEG,True)
cam.set(cv2.CAP_PROP_FPS,30)

So, the full code for basic camera reading is as follows:

import cv2

cam = cv2.VideoCapture(1)
cam.set(cv2.CAP_FFMPEG,True)
cam.set(cv2.CAP_PROP_FPS,30)

while(True):
    ret,frame = cam.read()
    cv2.imshow('frame',frame)
    if (cv2.waitKey(1) & 0xFF == ord('q')):
        break

cam.release()
cv2.destroyAllWindows()

You can then apply image processing operations as usual. Just for reference, this was my configuration:

  • Opencv 3.1.0
  • Python 2.7.5
  • Windows 8.1
  • Elgato Video Capture device (this was also shown as Sound Video & Game controllers)
Javier
  • 11
  • 2