Thursday, February 9, 2012

How Webcams Work



by Marshall Brain
If you have been exploring the Web for any length of time, then you have run across any number of Webcams in your travels. Webcams range from the silly to the serious -- a Webcam might point at a coffee pot or a space shuttle launch pad. There are business cams, personal cams, private cams, traffic cams... you name it and there's probably a Webcam pointed at it!
Have you ever considered setting up a Webcam yourself? You might want to create a silly cam by pointing it at your hamster or putting it inside your refrigerator. But it turns out there are lots of productive uses for Webcams, too. For example:
• You will be out of town for a week and you want to keep an eye on your house plants.
• You'd like to be able to check on the baby sitter and make sure everything is okay while you are at work.
• You'd like to know what your dog does in the back yard all day long.
• You want to let the grandparents watch the new baby during nap time.
If there is something that you would like to monitor remotely, a Webcam makes it easy!
In this article, we will look at the steps you can take to put up your own simple Web camera.
The Basic Idea Webcams, like most things, range from simple to complex. Let's start with simple.
A simple Webcam consists of a digital camera attached to your computer. Cameras like these have dropped well below $100 and they are easy to connect through a USB port (earlier cameras connected through a dedicated card or the parallel port). A piece of software connects to the camera and grabs a frame from it periodically. For example, the software might grab a still image from the camera once every 30 seconds. The software then turns that image into a normal JPG file and uploads it to your Web server. The JPG image can be placed on any Web page (for information on creating Web pages and adding JPG images, see How Web Pages Work).
If you don't have a Web server, several companies (like the makers of Webcam32) now offer you a free place to upload your images, saving you the trouble of having to set up and maintain a Web server or a hosted Web site.
This is the simplest possible Webcam. Putting a standard JPG image into a standard Web page is straightforward, but it has the disadvantage that your readers must manually refresh the image. Using a meta tag, a JavaScript function or a Java applet, it is possible to create a system that automatically refreshes the image for your readers.
What You Need In order for you to create a simple Webcam, you need three things:
1. A camera of some sort connected to your computer
2. A piece of software that can grab a frame from the camera periodically
3. A Web server
For some people, their home computer serves as their Web server. If that's the case, these three things are all that you need. If your Web server is hosted elsewhere (for example, because you are
paying an ASP to host your Web server), you also need:
4. The ability to move frames from your computer to the Web server, normally by File Transfer Protocol (FTP), although several other protocols are gaining favor as well. For most Web servers, this is no problem; but occasionally, a hosting company will have policies in place that make this difficult.
5. A relatively consistent connection between your computer and the Internet. A modem connection to an ISP is fine if it is something that you keep connected most of the time. This implies that you have a dedicated phone line for your computer or something like a cable modem that is connected all the time.
As mentioned previously, several companies (like the makers of Webcam32, who have a feature called AutoCam) now offer you a free place to upload your images. By using one of these services, you avoid having to host and/or maintain your own Web site. If you are using one of these services, then you need:
1. A camera of some sort connected to your computer
2. A piece of software that can grab a frame from the camera periodically
3. A relatively consistent connection between your computer and the Internet.
If your connection is not consistent, it won't hurt anything. It just means that the image cannot refresh itself all the time.
Putting it All Together In order to experiment with Webcams and go through the process of setting one up, HowStuffWorks got itself a Webcam. To set it up, here is what we did:
1. We went down to the local computer warehouse and bought the Intel PC Camera Pro Pack (USB).
2. We installed the software for the camera on a Windows 98 machine. This took two tries, and we learned that it is important to turn off the virus-checking software and do a fresh reboot before installing.
3. We went to the Web site www.webcam32.com and downloaded a program called Webcam32. This is a popular software package for Webcams. Webcam32 grabs pictures from the camera and uploads them to a Web server. You can get a free demo version or pay $25 for the full version. I paid $25 for a registered copy. (The complete user's manual for this product is available on the Web site -- it offers a nice suite of features.)
4. We installed Webcam32. It was a very easy installation.
5. After entering the address of the FTP site and a couple of other pieces of information, the HowStuffWorks Webcam showed its first signs of life!
6. We pointed the camera out the window.
7. We then tuned the software a bit to reduce the file size of the images and to enable the temporary-file copying feature.
There are many different features you can experiment with in Webcam32: streaming video, chat, captions, AVI files and different resolutions and compression ratios, to name a few. Webcam32 also supports the AutoCam feature, which allows you to create a Web page for your Webcam for free on their server. The software makes it simple.
As you can see, setting up a simple Webcam is extremely easy! If nothing else, the setup described here is a fun, inexpensive and simple way to experiment with a Webcam and see what you can do
with one of your own!
Automatic Refreshing The HowStuffWorks Webcam image on this page is a static image, and readers have to refresh the image manually (by pushing the Refresh button in the browser) if they want to see any changes. There are three different techniques you can use to create automatic refreshing:
• You can add a meta tag to the HTML for the page so that the page refreshes at some frequency. The tag to add is:
<meta http-equiv="refresh" content="30">
The "30" is the number of seconds between each refresh and can be set to anything you like. The entire page will reload every 30 seconds, so it is beneficial to keep the page short.
• You can add a Java applet to your site. The Webcam32 Online Help page explains how to obtain and install the free applet. The applet is a program that automatically fetches the image periodically. The advantage is that only the image refreshes, not the entire page. Most browsers support Java applets, so most of your readers will have no problem.
• You can use JavaScript, as demonstrated on this pagefrom JavaScript.Internet.com (look at the source code on this page). You can also check out How Java Works for a detailed look at Java programming.
External Webcams One problem with using a camera hooked to a computer via a USB cable is the limited cable length. What if the room you want to capture is at the other end of the house, or outside? In that case, you need to purchase a camera like the Intel PC Camera Pro Pack (USB), which has an external video jack. You have two options when choosing an external camera:
• You can place a standard camera anywhere in the house and run a video cable with RCA jacks on it from the camera to the computer. There are all sorts of places on the Web that sell small pinhole video cameras, either on their own or embedded in things like clocks and smoke detectors. You can find small security cameras priced between $100 and $200. This page from Amazon.com shows a few of the ones you can choose from.
• You can avoid the cable by using a radio link. This page has an example.
Monitoring is only one of the things you can do with your Webcam. There are any number of ways to make use of a camera that's connected to your computer. You can even get software that will let you make video phone calls!

How Bits and Bytes Work



by Marshall Brain
If you have used a computer for more than five minutes, then you have heard the words bits and bytes. Both RAM and hard disk capacities are measured in bytes, as are file sizes when you examine them in a file viewer.
You might hear an advertisement that says, "This computer has a 32-bit Pentium processor with 64 megabytes of RAM and 2.1 gigabytes of hard disk space." And many HowStuffWorks articles talk about bytes (for example, How CDs Work). In this article, we will discuss bits and bytes so that you have a complete understanding.
Decimal Numbers The easiest way to understand bits is to compare them to something you know: digits. A digit is a single place that can hold numerical values between 0 and 9. Digits are normally combined together in groups to create larger numbers. For example, 6,357 has four digits. It is understood that in the number 6,357, the 7 is filling the "1s place," while the 5 is filling the 10s place, the 3 is filling the 100s place and the 6 is filling the 1,000s place. So you could express things this way if you wanted to be explicit:
(6 * 1000) + (3 * 100) + (5 * 10) + (7 * 1) = 6000 + 300 + 50 + 7 = 6357
Another way to express it would be to use powers of 10. Assuming that we are going to represent the concept of "raised to the power of" with the "^" symbol (so "10 squared" is written as "10^2"), another way to express it is like this:
(6 * 10^3) + (3 * 10^2) + (5 * 10^1) + (7 * 10^0) = 6000 + 300 + 50 + 7 = 6357
What you can see from this expression is that each digit is a placeholder for the next higher power of 10, starting in the first digit with 10 raised to the power of zero.
That should all feel pretty comfortable -- we work with decimal digits every day. The neat thing about number systems is that there is nothing that forces you to have 10 different values in a digit. Our base-10 number system likely grew up because we have 10 fingers, but if we happened to evolve to have eight fingers instead, we would probably have a base-8 number system. You can have base-anything number systems. In fact, there are lots of good reasons to use different bases in different situations.
Bits Computers happen to operate using the base-2 number system, also known as the binary number system (just like the base-10 number system is known as the decimal number system). The reason computers use the base-2 system is because it makes it a lot easier to implement them with current electronic technology. You could wire up and build computers that operate in base-10, but they would be fiendishly expensive right now. On the other hand, base-2 computers are relatively cheap.
So computers use binary numbers, and therefore use binary digits in place of decimal digits. The word bit is a shortening of the words "Binary digIT." Whereas decimal digits have 10 possible values ranging from 0 to 9, bits have only two possible values: 0 and 1. Therefore, a binary number is composed of only 0s and 1s, like this: 1011. How do you figure out what the value of
the binary number 1011 is? You do it in the same way we did it above for 6357, but you use a base of 2 instead of a base of 10. So:
(1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (1 * 2^0) = 8 + 0 + 2 + 1 = 11
You can see that in binary numbers, each bit holds the value of increasing powers of 2. That makes counting in binary pretty easy. Starting at zero and going through 20, counting in decimal and binary looks like this:
0 = 0
1 = 1
2 = 10
3 = 11
4 = 100
5 = 101
6 = 110
7 = 111
8 = 1000
9 = 1001
10 = 1010
11 = 1011
12 = 1100
13 = 1101
14 = 1110
15 = 1111
16 = 10000
17 = 10001
18 = 10010
19 = 10011
20 = 10100
When you look at this sequence, 0 and 1 are the same for decimal and binary number systems. At the number 2, you see carrying first take place in the binary system. If a bit is 1, and you add 1 to it, the bit becomes 0 and the next bit becomes 1. In the transition from 15 to 16 this effect roles over through 4 bits, turning 1111 into 10000.
Bytes Bits are rarely seen alone in computers. They are almost always bundled together into 8-bit collections, and these collections are called bytes. Why are there 8 bits in a byte? A similar question is, "Why are there 12 eggs in a dozen?" The 8-bit byte is something that people settled on through trial and error over the past 50 years.
With 8 bits in a byte, you can represent 256 values ranging from 0 to 255, as shown here:
0 = 00000000
1 = 00000001
2 = 00000010
...
254 = 11111110
255 = 11111111
In the article How CDs Work, you learn that a CD uses 2 bytes, or 16 bits, per sample. That gives each sample a range from 0 to 65,535, like this:
0 = 0000000000000000
1 = 0000000000000001
2 = 0000000000000010
...
65534 = 1111111111111110
65535 = 1111111111111111
Bytes are frequently used to hold individual characters in a text document. In the ASCII character set, each binary value between 0 and 127 is given a specific character. Most computers extend the ASCII character set to use the full range of 256 characters available in a byte. The upper 128 characters handle special things like accented characters from common foreign languages.
You can see the 127 standard ASCII codes below. Computers store text documents, both on diskand in memory, using these codes. For example, if you use Notepad in Windows 95/98 to create a text file containing the words, "Four score and seven years ago," Notepad would use 1 byte of memory per character (including 1 byte for each space character between the words -- ASCII character 32). When Notepad stores the sentence in a file on disk, the file will also contain 1 byte per character and per space.
Try this experiment: Open up a new file in Notepad and insert the sentence, "Four score and seven years ago" in it. Save the file to disk under the name getty.txt. Then use the explorer and look at the size of the file. You will find that the file has a size of 30 bytes on disk: 1 byte for each character. If you add another word to the end of the sentence and re-save it, the file size will jump to the appropriate number of bytes. Each character consumes a byte.
If you were to look at the file as a computer looks at it, you would find that each byte contains not a letter but a number --the number is the ASCII code corresponding to the character (see below). So on disk, the numbers for the file look like this:
F o u r a n d s e v e n
70 111 117 114 32 97 110 100 32 115 101 118 101 110
By looking in the ASCII table, you can see a one-to-one correspondence between each character and the ASCII code used. Note the use of 32 for a space -- 32 is the ASCII code for a space. We could expand these decimal numbers out to binary numbers (so 32 = 00100000) if we wanted to be technically correct -- that is how the computer really deals with things.
Standard ASCII Character Set The first 32 values (0 through 31) are codes for things like carriage return and line feed. The space character is the 33rd value, followed by punctuation, digits, uppercase characters and lowercase characters.
0 NUL
1 SOH
2 STX
3 ETX
4 EOT
5 ENQ
6 ACK
7 BEL
8 BS
9 TAB
10 LF
11 VT
12 FF
13 CR
14 SO
15 SI
16 DLE
17 DC1
18 DC2
19 DC3
20 DC4
21 NAK
22 SYN
23 ETB
24 CAN
25 EM
26 SUB
27 ESC
28 FS
29 GS
30 RS
31 US
32
33 !
34 "
35 #
36 $
37 %
38 &
39 '
40 (
41 )
42 *
43 +
44 ,
45 -
46 .
47 /
48 0
49 1
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
58 :
59 ;
60 <
61 =
62 >
63 ?
64 @
65 A
66 B
67 C
68 D
69 E
70 F
71 G
72 H
73 I
74 J
75 K
76 L
77 M
78 N
79 O
80 P
81 Q
82 R
83 S
84 T
85 U
86 V
87 W
88 X
89 Y
90 Z
91 [
92 \
93 ]
94 ^
95 _
96 `
97 a
98 b
99 c
100 d
101 e
102 f
103 g
104 h
105 i
106 j
107 k
108 l
109 m
110 n
111 o
112 p
113 q
114 r
115 s
116 t
117 u
118 v
119 w
120 x
121 y
122 z
123 {
124 |
125 }
126 ~
127 DEL
Lots of Bytes When you start talking about lots of bytes, you get into prefixes like kilo, mega and giga, as in kilobyte, megabyte and gigabyte (also shortened to K, M and G, as in Kbytes, Mbytes and Gbytes or KB, MB and GB). The following table shows the multipliers:
Name
Abbr.
Size
Kilo
K
2^10 = 1,024
Mega
M
2^20 = 1,048,576
Giga
G
2^30 = 1,073,741,824
Tera
T
2^40 = 1,099,511,627,776
Peta
P
2^50 = 1,125,899,906,842,624
Exa
E
2^60 = 1,152,921,504,606,846,976
Zetta
Z
2^70 = 1,180,591,620,717,411,303,424
Yotta
Y
2^80 = 1,208,925,819,614,629,174,706,176
You can see in this chart that kilo is about a thousand, mega is about a million, giga is about a billion, and so on. So when someone says, "This computer has a 2 gig hard drive," what he or she means is that the hard drive stores 2 gigabytes, or approximately 2 billion bytes, or exactly 2,147,483,648 bytes. How could you possibly need 2 gigabytes of space? When you consider that one CD holds 650 megabytes, you can see that just three CDs worth of data will fill the whole thing! Terabyte databases are fairly common these days, and there are probably a few petabyte databases floating around the Pentagon by now.
Binary Math Binary math works just like decimal math, except that the value of each bit can be only 0 or 1. To get a feel for binary math, let's start with decimal addition and see how it works. Assume that we want to add 452 and 751:
452
+ 751
---
1203
To add these two numbers together, you start at the right: 2 + 1 = 3. No problem. Next, 5 + 5 = 10, so you save the zero and carry the 1 over to the next place. Next, 4 + 7 + 1 (because of the carry) = 12, so you save the 2 and carry the 1. Finally, 0 + 0 + 1 = 1. So the answer is 1203.
Binary addition works exactly the same way:
010
+ 111
---
1001
Starting at the right, 0 + 1 = 1 for the first digit. No carrying there. You've got 1 + 1 = 10 for the second digit, so save the 0 and carry the 1. For the third digit, 0 + 1 + 1 = 10, so save the zero and carry the 1. For the last digit, 0 + 0 + 1 = 1. So the answer is 1001. If you translate everything over to decimal you can see it is correct: 2 + 7 = 9.
To see how boolean addition is implemented using gates, see How Boolean Logic Works.
Quick Recap
• Bits are binary digits. A bit can hold the value 0 or 1.
• Bytes are made up of 8 bits each.
• Binary math works just like decimal math, but each bit can have a value of only 0 or 1.
There really is nothing more to it -- bits and bytes are that simple!

How 3-D PC Glasses Work


by Shane Speck
Only a few years ago, seeing in 3-D meant peering through a pair of red-and-blue glasses, or trying not to go cross-eyed in front of a page of fuzzy dots. It was great at the time, but 3-D technology has moved on. Scientists know more about how our vision works than ever before, and our computers are more powerful than ever before -- most of us have sophisticated components in our computer that are dedicated to producing realistic graphics. Put those two things together, and you'll see how 3-D graphics have really begun to take off.
Most computer users are familiar with 3-D games. Back in the '90s, computer enthusiasts were stunned by the game Castle Wolfenstein 3D, which took place in a maze-like castle. It may have been constructed from blocky tiles, but the castle existed in three dimensions -- you could move forward and backward, or hold down the appropriate key and see your viewpoint spin through 360 degrees. Back then, it was revolutionary and quite amazing. Nowadays, gamers enjoy ever more complicated graphics -- smooth, three-dimensional environments complete with realistic lighting and complex simulations of real-life physics grace our screens. But that's the problem -- the screen. The game itself may be in three dimensions, and the player may be able to look wherever he wants with complete freedom, but at the end of the day the picture is displayed on a computer monitor...and that's a flat surface.
That's where PC 3-D glasses come in. They're designed to convince your brain that your monitor is showing a real, three-dimensional object. In order to understand quite how this works, we need to know what sort of work our brain does with the information our eyes give it. Once we know about that, we'll be able to understand just how 3-D glasses do their job.
Seeing in Three Dimensions Human beings, like most other creatures, are equipped with two eyes, situated close together and side by side. This positioning means that each eye has a view of the same area from a slightly different angle. You can check this out by focusing on a distant object and viewing through each eye alternately -- see how some things seem to change position slightly?
The brain takes the information from each eye and unites them into one picture, interpreting the slight differences between each view as depth. This produces a three-dimensional picture: one with height, width and depth.
Photo courtesy Amazon.com E-Dimensional Wireless E-D Glasses eDimensional, E-D and the eDimensional logos are registered trademarks of eDimensional, Inc. in the U.S. and other countries.
It is the added perception of depth that makes 3-D, or stereoscopic, vision so important. With
stereoscopic vision, we see exactly where our surroundings are in relation to our own bodies,
usually with considerable precision. We are particularly good at spotting objects that are moving
toward or away from us, and the positioning of our eyes means we can see partially around solid
objects without needing to move our heads. It's easy to see why some people believe
stereoscopic vision evolved as a means of survival.
Certainly, stereoscopic vision is vital for seemingly simple actions such as throwing, catching or
hitting a ball, driving or parking a car, or even just threading a needle. That's not to say such
tasks can't be managed without 3-D vision, but a lack of depth perception can make these
everyday tasks much more complex.
A Different Point Of View
The key to stereoscopic vision is depth, and our brain will
happily take care of that for us, providing our eyes are given the
right information in the first place. This is exactly how those redand-
blue glasses work -- each color filters out part of the image,
giving each eye a slightly different view. The brain puts the two
different images together, and those blue-and-red blurry
images turned into a fantastic 3-D comic, or movie, or TV show.
Stereograms, also known as Magic Eye pictures, use
seemingly-random patterns of dots but rely on the viewer to cross his eyes in just the right way, or
to look through the image until the eyes see just the right part and allow the brain to decode the
hidden depth information.
Both methods have their disadvantages, of course -- the red-and-blue glasses make it difficult to
show color in the 3-D image, and viewing stereograms is an art in itself. Neither method is entirely suitable for playing games.
Nevertheless, the underlying principle is exactly the same: creating and controlling those two different points of view. But just how easy is it to create these two separate images, one for each eye?
The answer is all about how games are created. Not so long ago, the graphics we saw on our computer screens were carefully drawn into the computer -- every single frame of animation, every different view of a character. If you wanted a dinosaur in your game, you sat down and drew the different views of a dinosaur into the computer.
Nowadays, games designers sit down with a 3-D graphics package and design their dinosaur in three dimensions. Once that's done, they needn't worry about the different views -- the computer has a 3-D model of the dinosaur in its memory, and the game simply works out where the player is looking and draws the correct view of the dinosaur using the 3-D model. In fact, everything you see on your screen in a modern 3-D game is produced the same way; the game is like a gigantic 3-D model. The computer works out what it needs to display on your screen and generates the appropriate view.
Since the computer is quite happy to create one point of view, there's no problem shifting the viewpoint slightly and creating another point of view. And after that, all you need is a way to get the correct image to the correct eye.
Getting Synched It's all down to the power of liquid crystal displays, or LCD. Just like the liquid crystal in a watch can be changed from transparent to black, the lenses of PC 3-D glasses can be transparent or opaque. In other words, the glasses can control which eye sees the image on the screen, and with careful timing you've got perfect 3-D. Here's how it happens:
1. The images are prepared by the computer and displayed.
Two images are generated, representing the views seen by each eye:
Both of these views are presented on the screen in rapid sequence:
2. While the left view is presented, the right eye is blocked by the LCD glasses. Similarly, when the right view is presented, the left eye is blocked.
All of this happens so quickly that the brain is entirely unaware of the two images merging together into a stereoscopic view. This is the same thing as when we watch a film using an old film projector and the sequence of still images flickering onto the screen merges together to form a movie.
A Brief History Of 3-D Glasses So, we've seen that although there might be something complex going on behind the scenes, with the right equipment we can just sit back and let our eyes do the work. Of course, the technology wasn't always so simple; there have, in fact, been four generations leading up to today's 3-D glasses.
The first generation modified the games themselves to make them compatible with stereoscopic 3-D. The games' creators had to specifically support each type of LCD glasses -- hardly an ideal situation. There was no guarantee that the glasses you'd bought would work with your favorite game. As you can imagine, that didn't appeal to many people; so a second solution was developed.
This second solution was to override the game, actually taking over the computer's screen and altering what was displayed. As far as the game was concerned, it was just doing what it normally did, except, of course, that some of the computer's time was taken up processing the image to make it 3-D. The result was slower performance and low-resolution, blocky images. It did work with hundreds of games, though, and that was a definite improvement.
The third generation worked in a similar way, modifying the graphics driver but also maintaining the resolution of the images -- no more blocky graphics! Unfortunately, it wasn't compatible with many games, though it was a definite forerunner to the 3-D glasses we have nowadays.
In the fourth-generation models, compatibility is high, the complicated work is done by the graphics card, and the lightweight LCD glasses flick so rapidly between the two images that all we see is crystal-clear, 3-D images.
So what's on the market? What should you look for? Let's find out...
Buying
Although the basic technology is the same, there is a range of different glasses out there. You'll find lightweight, wireless glasses, as well as more basic (and therefore cheaper) pairs. The view through the glasses depends more on your computer's graphics card than the make of glasses, but you will find that different manufacturers offer extra software or other minor incentives. The lesson is: Shop around! If you get the chance to try a pair out before buying, don't hesitate -- try to imagine wearing them for an hour of intensive gaming. You might want to put in the extra money for a slightly better model.
Bear in mind, too, that all glasses come with the standard video game warning concerning epilepsy, eye-strain and tiredness. If you generally find it difficult to cope with a standard flat monitor, you will definitely want to try out the glasses before you buy. Be wary also if you have an LCD flat-panel monitor, because current 3-D glasses don't work well with this kind of monitor. Be sure to check compatibility before you buy.
Check out exactly which kind of video card you have (manufacturer and model) and do a little bit of research before you make your purchase. The X-Force 3D Game Glasses, for example, will only work with nVidia video cards. Many glasses will work with various graphics cards, but the only way to tell for sure is to read the side of the box carefully.