Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
637 views
in Technique[技术] by (71.8m points)

opencv - grab frame NTSCtoUSB dongle, opencv2, python wrapper

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: ........opencvmoduleshighguisrcwindow.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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. (!)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...