Ruby + USB + CCTV Camera Driver?

I want to write a Ruby driver that handles the feed from A CCTV camera.
The camera's output is through a BNC connector. I figure I'd solder up a
BNC - USB adapter that connects the BNC to pins 2 & 3 of the USB. The
camera has separate power, so USB power is not required.

I am looking for ideas on how to use Ruby to read the USB port and
convert the signal coming in to a live video that I can display on the
PC monitor.

Any ideas?

Thanks,

--Bob

···

--
Posted via http://www.ruby-forum.com/.

I googled for "Ruby USB" and found this: http://www.a-k-r.org/ruby-usb/

Are you sure your camera actually delivers a digital signal and not analog video or an RF modulated signal?

···

On 2011-07-18 1:00 PM, Bob Carpenter. wrote:

I want to write a Ruby driver that handles the feed from A CCTV camera.
The camera's output is through a BNC connector. I figure I'd solder up a
BNC - USB adapter that connects the BNC to pins 2& 3 of the USB. The
camera has separate power, so USB power is not required.

I am looking for ideas on how to use Ruby to read the USB port and
convert the signal coming in to a live video that I can display on the
PC monitor.

Any ideas?

Thanks,

--Bob

Bob Carpenter. wrote in post #1011453:

I want to write a Ruby driver that handles the feed from A CCTV camera.
The camera's output is through a BNC connector. I figure I'd solder up a
BNC - USB adapter that connects the BNC to pins 2 & 3 of the USB.

Why not try wiring the centre pin of the BNC to Live, and the outer
shield to Neutral, then plug into a 110-240V supply. (But make sure you
wire it that way round, so you're less likely to electrocute yourself)

Or you could connect the two wires to that little light which is inside
your fridge, and then close the door. This is useful as it lets you
check on the status of your food, without having to open it up.

Really, you can connect anything to anything - It Just Works [TM].

···

--
Posted via http://www.ruby-forum.com/\.

Steve Klabnik wrote in post #1011458:

I googled for "Ruby USB" and found this: ruby-usb - libusb binding for Ruby

I looked into libusb a month or so ago. Seems incomplete and no actual
Ruby examples were found. So not sure how to actually use it.

Solving the USB connection is part of the problem - probably the easy
part - converting the data coming in to a video format will be the more
difficult task.

Thanks,

--Bob

···

--
Posted via http://www.ruby-forum.com/\.

William Rutiser wrote in post #1011466:

Thanks,

--Bob

Are you sure your camera actually delivers a digital signal and not
analog video or an RF modulated signal?

It is a digital camera, here are the specs:

Horizontal resolution: 420TVL 480TVL 540TVL 600TVL 420TVL
Imaging device: 1/3" SONY SuperHAD CCD 1/4 SHARP
Sensing Area:: 4.9mm(H)×3.7mm(V)
Pixels: PAL:752(H)×582(V) PAL:500(H)×582(V)
NTSC: 768(H) × 494(V) NTSC :510(H) × 494(V)
TV system: PAL/NTSC
Minimum illumination: IR ON Olux
SNR: More than 48dB
Electronic shutter: PAL:1/50s-1/100.000s
Gamma correction: 0.45
Gain control: Auto
White balance: Auto
Backlight compensation: Auto
Synchronization system: Internal Synchronization
Lens: 3.6 /6 /8 MM optional
Video output: 1.0vp-p.75O,BNC Connector
IR Distance: 20M Infrared Detection range 30
IR LEDs: F8×22
Protection class: Ip66
Power: DC 12V ±10%
Current consumption: 90mA(IR ON MAX 470mA)

The supplier (Chinese) does not provide any more details than what I
have posted above. Sony produces the camera, and does provide fairly
detailed docs, but I am not yet sure which specific model, out of dozens
they produce, that I have received from the Chinese supplier. I have a
unit in-hand, hoping to get this to work for a security camera idea I
have.

Thanks,

--Bob

···

On 2011-07-18 1:00 PM, Bob Carpenter. wrote:

--
Posted via http://www.ruby-forum.com/\.

Hm, well, maybe the serialport gem would work? I mean, USB is serial,
right? This isn't an area I'm super familiar with.

Do you have any idea what format the video is in? My first instinct is
to use ffmpeg...

That sure sounds analog to me :slight_smile:

···

On Mon, Jul 18, 2011 at 11:51 AM, Bob Carpenter. <rgc3679@yahoo.com> wrote:

Are you sure your camera actually delivers a digital signal and not
analog video or an RF modulated signal?

It is a digital camera, here are the specs:

Video output: 1.0vp-p.75O,BNC Connector

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan

Hassan Schroeder wrote in post #1011472:

Are you sure your camera actually delivers a digital signal and not
analog video or an RF modulated signal?

It is a digital camera, here are the specs:

Video output: 1.0vp-p.75O,BNC Connector

That sure sounds analog to me :slight_smile:

Does that means 1.0 volt peak-to-peak at 750 Ohms?

How do you take the voltage coming in to the USB 2 & 3 pins and convert
to digital?

All the cameras I looked at had similar specs - not being a EE type I
thought it was software's job to convert to a digital signal.

Thanks,

--Bob

···

On Mon, Jul 18, 2011 at 11:51 AM, Bob Carpenter. <rgc3679@yahoo.com> > wrote:

--
Posted via http://www.ruby-forum.com/\.

Uh, no. Short version, you need hardware to digitize the incoming
analog signal (which in your case appears to be standard TV, either
NTSC or PAL).

What you do with the digitized data is dependent on the software
you use or write, but you need it digitized first.

Or get a camera that includes digital output from the get-go :slight_smile:

···

On Mon, Jul 18, 2011 at 12:58 PM, Bob Carpenter. <rgc3679@yahoo.com> wrote:

All the cameras I looked at had similar specs - not being a EE type I
thought it was software's job to convert to a digital signal.

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan

To make this even worse: You need an analog-digital converter that is
able to digitize the signal in the first place, and those chips are
single-trick ponies (i.e. an ADC tuned for TV signals won't work with
FM radio, even if the output signals you'd need *were* identical,
which they aren't).

Rolling your own is possible but hardly cost-effective, unless you do
this sort of thing as a hobby, of course.

···

On Tue, Jul 19, 2011 at 12:18 AM, Hassan Schroeder <hassan.schroeder@gmail.com> wrote:

What you do with the digitized data is dependent on the software
you use or write, but you need it digitized first.

--
Phillip Gawlowski

phgaw.posterous.com | twitter.com/phgaw | gplus.to/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
-- Leibniz

Phillip Gawlowski wrote in post #1011503:

What you do with the digitized data is dependent on the software
you use or write, but you need it digitized first.

To make this even worse: You need an analog-digital converter that is
able to digitize the signal in the first place, and those chips are
single-trick ponies (i.e. an ADC tuned for TV signals won't work with
FM radio, even if the output signals you'd need *were* identical,
which they aren't).

It's not clear whether you guys think a software ADC is impractical or
whether it's impossible.

If you're saying it's impractical, is it due to performance - takes too
long to convert analog voltages to digital values?

If it's impossible, is it because reading voltages at USB pins cannot be
done in software?

I have not found any reasonably priced digital cameras - reasonable
being in the range of $50/unit for quantities of 100. Please let me know
if you have seen any.

Thanks,

--Bob

···

On Tue, Jul 19, 2011 at 12:18 AM, Hassan Schroeder > <hassan.schroeder@gmail.com> wrote:

--
Posted via http://www.ruby-forum.com/\.

If it's impossible, is it because reading voltages at USB pins cannot be
done in software?

Shortest possible answer: Yes.

I have not found any reasonably priced digital cameras - reasonable
being in the range of $50/unit for quantities of 100. Please let me know
if you have seen any.

Haven't had a reason to look :slight_smile:

Good luck!

···

On Mon, Jul 18, 2011 at 5:20 PM, Bob Carpenter. <rgc3679@yahoo.com> wrote:

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan

It's not clear whether you guys think a software ADC is impractical or
whether it's impossible.

It's not impossible. It's just so very impractical that it might as well be.

If you're saying it's impractical, is it due to performance - takes too
long to convert analog voltages to digital values?

Yes.

If it's impossible, is it because reading voltages at USB pins cannot be
done in software?

That, too, more or less.

The third problem is that USB isn't even capable of *reading*
different voltages, much less a waveform! It can read an on state and
an off state. Analog signals are "composites" of different wave
lengths--you have electrical power as carrier wave, on top of which
you modulate all your other waves carrying actual data--which a
digital connection just can't handle (after all, that's what ADC/DAC
chips are for ;).

I have not found any reasonably priced digital cameras - reasonable
being in the range of $50/unit for quantities of 100. Please let me know
if you have seen any.

If the problem is digitizing the video signal:

Get or build a DVR, and pull the already-encoded video from that. It's
cheaper and less headache-y that way. You'll probably need that
anyway, since CCTV usually means "surveillance", and *that* again
means "recording evidence for the police / court".

···

On Tue, Jul 19, 2011 at 2:20 AM, Bob Carpenter. <rgc3679@yahoo.com> wrote:

--
Phillip Gawlowski

phgaw.posterous.com | twitter.com/phgaw | gplus.to/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
-- Leibniz

Bob Carpenter. wrote in post #1011512:

I have not found any reasonably priced digital cameras - reasonable
being in the range of $50/unit for quantities of 100. Please let me know
if you have seen any.

Bog-standard "webcams" are about half that price, and plug straight into
a USB port. You can start by using "Zoneminder" to drive them - pretty
cool software, but written in PHP. From that you can work out how to
drive them in Ruby if you need.

However, they are quite CPU-intensive to read, and it may not work well
if you have more than two or three of them on one PC.

There are ethernet-attached webcams which are not much more expensive
than your target price, and give you a motion-JPEG stream output. I'm
just racking my brains now to try and remember what the one I found was;
I've a vague idea that it was by Edimax. The Zoneminder site may give
you some pointers, or google "low-cost IP camera"

Regards,

Brian.

···

--
Posted via http://www.ruby-forum.com/\.

Ones which turn up in a quick search: Plantex CS-TX04F, Edimax IC-3005
or IC-3005WN (latter is wireless), D-Link DCS-900.

···

--
Posted via http://www.ruby-forum.com/.

Phillip Gawlowski wrote in post #1011518:

The third problem is that USB isn't even capable of *reading*
different voltages, much less a waveform! It can read an on state and
an off state. Analog signals are "composites" of different wave
lengths--you have electrical power as carrier wave, on top of which
you modulate all your other waves carrying actual data--which a
digital connection just can't handle (after all, that's what ADC/DAC
chips are for ;).

Thanks for the education - very much appreciated!

I will look for fully digital cameras or an inexpensive way to do ADC,
maybe via add-on board. Brian Candler has suggested several cameras that
I will look into.

Thanks,

--Bob

···

--
Posted via http://www.ruby-forum.com/\.

Brian Candler wrote in post #1011575:

Bob Carpenter. wrote in post #1011512:

I have not found any reasonably priced digital cameras - reasonable
being in the range of $50/unit for quantities of 100. Please let me know
if you have seen any.

Bog-standard "webcams" are about half that price, and plug straight into
a USB port. You can start by using "Zoneminder" to drive them - pretty
cool software, but written in PHP. From that you can work out how to
drive them in Ruby if you need.

However, they are quite CPU-intensive to read, and it may not work well
if you have more than two or three of them on one PC.

There are ethernet-attached webcams which are not much more expensive
than your target price, and give you a motion-JPEG stream output. I'm
just racking my brains now to try and remember what the one I found was;
I've a vague idea that it was by Edimax. The Zoneminder site may give
you some pointers, or google "low-cost IP camera"

Regards,

Brian.

Thanks Brian! I will study these cameras and start looking in this
direction. The CPU won't be a problem, and neither will PHP.

Thanks,

--Bob

···

--
Posted via http://www.ruby-forum.com/\.

Thanks for the education - very much appreciated!

You are welcome! Though, it is a really, really abbreviated
explanation, as well (look ma, no complex numbers).

I will look for fully digital cameras or an inexpensive way to do ADC,
maybe via add-on board.

Unless you want to retro-fit what you already have, I wouldn't bother.
The benefit of digital cameras is that the signal processing is done
in the camera, and the camera can apply some corrections already (low
light conditions, colour correction, whathaveyou), which means that
all you need to do is watch the images. Laziness *can* be a virtue. :wink:

Though, you know your deployment situation best, obviously enough.

···

On Tue, Jul 19, 2011 at 4:39 PM, Bob Carpenter. <rgc3679@yahoo.com> wrote:

--
Phillip Gawlowski

phgaw.posterous.com | twitter.com/phgaw | gplus.to/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
-- Leibniz

Phillip Gawlowski wrote in post #1011653:

Unless you want to retro-fit what you already have, I wouldn't bother.
The benefit of digital cameras is that the signal processing is done
in the camera, and the camera can apply some corrections already (low
light conditions, colour correction, whathaveyou), which means that
all you need to do is watch the images. Laziness *can* be a virtue. :wink:

I agree, too much trouble trying to retrofit an analog to my product.
I've found a good supply of IP cameras and will start looking down that
path. Here's specs for one I like:

Image Device SONY Super HAD CCD 1/3 SONY CCD
Effective Pixels (H x V)
PAL: 352 x 288 (CIF), 704 x 288 (2CIF), 704 x 576 (D1)
NTSC: 352 x 240 (CIF), 704 x 240 (2CIF), 704 x 480 (D1)

Signal System PAL/ NTSC
Horizontal Resolution 540TVL 520TVL 500TVL 420TVL
Minimum Illumination 0Lux (IR On)
Video Compression H.264 Main Profile3.0
Dual Streaming H.264 & MJPEG
Video Parameters Brightness, Hue, Contrast, Saturation, Image quality
Streaming Format Optional Video Streaming or Audio & Video composite
Streaming
Video Frame Rate PAL: 1-25 fps; NTSC: 1-30 fps
Video Compression Bit Rate 30Kbit/S - 16Mbit/S
Audio Input 1 channel, linear Input
Audio Compression G.726, G.711, ADPCM
Audio Output 1 channel, RCA interface, linear output
Audio Two-way Talk Built in Audio I/O port
Supported Protocols
TCP, UDP, IP, HTTP, FTP, SMTP, DHCP, DNS, ARP, ICMP, POP3, NTP, IPsec,
UPNP, RTP, RTCP,
RTSP.
10M/100M self-adapting Ethernet port
1x RS485 port, 1 RS232 port (supports transparent protocols)
System Interface
Embedded SD cad slot

Do you think I'll be able to access the ethernet port with Ruby? Or do
you see a better way to grab the image stream? Googling for Ruby
ethernet didn't yield much, but I'll keep digging.

BTW: I'm using Ubuntu Linux for the system.

Thanks,

--Bob

···

--
Posted via http://www.ruby-forum.com/\.