S-Video
S-Video is an analog interface. It can only transmit video files of standard definition television (576i and 480i), which means that modern speech quality formats are out of the question. TVs are rarely equipped with such a port, therefore, in order to project an image from a laptop, an S-Video to RCA adapter is additionally required. Also, do not use an S-Video cable longer than 2 meters, as this will degrade the signal quality. To transfer sound to TV, similar to DVI, you will need to use a “minijack”.

After connecting the cable, you always need to install the video source on the TV
Let’s look at how you can output an image to a TV via USB. In this case, with a USB-USB connection, it will be impossible to view video, since this standard is not designed for video data transmission. In this option, you can view images, presentations, text documents. With this connection, the TV will see the laptop as a USB flash drive.
But to duplicate the laptop display, you can use the output to the TV’s HDMI port. To do this, you need an adapter, which is an external video card. You will need to install the driver from the video card to the laptop. When purchasing such an adapter, you should pay attention to the characteristics of the transmitted video (Full HD support) and sound.
We have already considered the connection using a local network wirelessly. Lan is a network but wired (Ethernet) connection. If the TV does not have a Wi-Fi module, then you can use this method. To mirror the computer screen to the TV, you will need to follow the same steps as for the WI – FI connection. Namely:
- Connect TV to the router using a network cable. In this case, the Dynamic Host Configuration Protocol (DHCP) must be configured on the network device. Otherwise, you will have to manually register the network settings in TV;
- Connect your laptop to the same network. Wired or wireless. it doesn’t matter;
- Install the program on the laptop to output files to TV. We’ve already covered the Home Media Server application, which is easy to set up and install;
- Share the required folders. That’s it, now you can transfer images and send video for playback.
How is it possible to transfer an image from a computer to a TV using VGA? The VGA standard only allows the transmission of an analog signal without sound. To reproduce sound, you will need an additional adapter with the so-called “tulips” or “minijack” plug. Another option is to leave the sound playing on the laptop or through the speakers connected to it. To do this, you can use the function keys of the laptop. It should display 2 screens, for example, F10Fn (function enable key). It is now possible to display videos from a laptop on a TV. When setting up display on a laptop, you can increase the resolution to get a better picture.
With any cable connection, you will have to adjust the screens on your laptop or PC
The color image is formed by means of three main signals: Red, Green, Blue. If the image is output from such a connector, then it is logical to use the same TV input. RGB replaced Scart when Scart became impossible to use in thin TVs. Mostly RGB is available on older models. Compatible with Scart and composite RCA (tulip) cables. Videos or games from the computer monitor to the TV will be broadcasted as with any other cable connection.
9 ways to transfer images from your computer to your TV screen
The laptop is very convenient for work with its dimensions and low weight. But when it comes to watching videos or playing games, you want to replace a small monitor with a larger screen. In case you have a TV with a large diagonal, you can connect your device to a TV or home theater. In the article, we will consider how you can display an image from a laptop on a TV.
Determine available connections
To transfer an image from a laptop to a TV, you need to find out what methods are available for this. First, you should see what ports are present on the TV and laptop, and then decide how best to duplicate the laptop screen.
Ways to display images from a laptop on TV
There are wireless and wired methods for displaying images from a laptop to a TV. With a wired connection, you do not need to have the same ports on both devices. If they are different, then you will need to use adapters. If you need to translate digital data to an analog input, you will need additional converters or attachments.
The disadvantages of a wireless connection are limited bandwidth and possible signal interruption. The disadvantage of connecting via a cord may be the presence of the cord itself, as well as the cable length limit for different standards. However, if you need to connect a laptop and enjoy viewing, this drawback is completely weightless and will not cause inconvenience.
All modern TVs are equipped with DLNA technology, which allows devices to exchange data within the home network. This can be done both via cable and WI-FI. If there is a connection via WI-FI, then both the laptop and TV must be connected to it. But the TV will only “see” the shared folders. In order for the TV to have access to all the information, you can open shared access to all folders in the “Network” settings on the laptop. But this is not recommended for security reasons. After all, in this case, everyone who will be connected to your network will be able to use your data. Another option is to make a specific folder publicly available.
But for a more convenient display of the image on the TV, it is better to download the program. One of the recommended ones is Home Media Server. It is free and universal for different TV models, and also has wide functionality. To install on a laptop, just download the application (better on the official website) and run the installation file. After starting the program in the settings window, you can select the category of media resources and already specify access to the folders there.
If your devices support Miracast or Intel WiDi technologies, then it is enough to enable these functions on the TV. Then he will be able to connect wirelessly to your laptop without a router, directly. On the laptop, however, you need to install the appropriate application. But when connected, you can display any picture from a laptop.
If the TV does not have a WI-FI module, then you can use various adapters that can be connected to the HDMI port. For example, one such device is the Google Chromecast, which looks like a USB flash drive. The gadget is designed for streaming multimedia content.
The connection via HDMI can be called optimal in order to transfer media data from one equipment to another. This standard provides high-speed transmission, even of files in ultra HD-quality, and transmits not only video, but also multichannel audio.
How to output images from a computer to a TV using HDMI? It is enough to connect the two devices with a cable. Then switch to TV AVI mode and select the port to which the cord is connected. On a laptop, you need to call the screen settings and set the required resolution there, as well as select the display of displays. This means that on a laptop you will be able to control both screens, and you will need to select a display for the TV screen. The options are:
- Duplications. the same image on both screens;
- Display on 1 screen. the second one will be turned off;
- Screen Enhancements. TV will become a second monitor.
The settings may vary depending on the version of the operating system.
For any wired connection, the devices must be disconnected before connecting them
The next way is how to transfer the image via DVI. The DVI standard was developed for transferring video content to digital devices. Predecessor to HDMI. And, unlike the latter, it does not transmit sound. In this case, you will need a TRS connector or adapter, otherwise called “minijack”. a very popular audio connector, probably familiar to many as an input for connecting headphones. To duplicate the screen of a computer or laptop, you will need to follow the same steps as for HDMI. Once connected, transferring the playback file is easy.
Scart
Scart is a European standard for transmitting analog and digital signals. It has different specifications, therefore, it can transmit different signals (audio channel, video, control). The convenience of the interface is that it makes it possible to connect a high-quality RGB video source to the TV without intermediate coding.
To broadcast a movie from a PC or laptop, it is better to use a VGA-SCART adapter. This is due to the fact that a large number of TVs are equipped with a SCART connector, and computers. VGA.
If you have a large number of connectors, it is better to choose a wired connection from the latest technologies. The best option is HDMI. In general, setting up your laptop and TV is straightforward. The main thing is to select the input signal on the TV, and on the laptop perform the settings that are required for the corresponding technology.
Connecting an analog camera to a monitor
To correctly and effectively connect the monitor to the camcorder, you need:
- connecting cables;
- Power Supply.
It should be understood that the quality of the image and the durability of the system largely depend on the quality of the cable used. Not worth saving. It is better to spend money on an expensive cable once than to periodically repair the entire system. To connect analog cameras, a coaxial cable is usually used.
There are 3 ways to connect a monitor and a video camera:
- using a video recorder;
- via PC settings (video capture card);
- direct connection.
The first method is justified when organizing surveillance, in which a large number of video cameras are involved. For systems consisting of 1 or a pair of cameras, it is not justified due to the high cost of the DVR.
Connection diagram of the monitor to the recorder
To connect cameras using a personal computer, you need a special video capture card or USB converter, which also implies additional expenses.
The best option for monitoring a house or apartment would be to connect the camera directly to the monitor. This method will allow you to observe on the monitor what is happening in the surveillance area of the camera at the moment. Online image viewing on the Internet will be unavailable.
You can use the screen of an ordinary personal computer, that is, the camera can be connected to an ordinary computer monitor directly. Additionally, you only need to purchase a BNC-VGA converter. It converts the analog camera signal to digital, which allows you to get the picture on the screen in real time. When buying it, it is important to pay attention to the resolution, which rarely exceeds 740×567 pixels. This means that regardless of the screen resolution, some of the quality will be “eaten” by the device. Higher quality converters will cost more.
BNC-VGA Signal Converter
To connect to the screen, it must have a composite signal connector. In it, the central contact feeds directly the video signal, and the external contact feeds the screen.
When connecting analog CCTV cameras, it is worth remembering that they usually have wire leads or a BNC connector. This means that to connect, you need to make a suitable adapter. Then BNC is installed on one side of the connecting cable, on the other. tulip (RCA) and they are connected. Voltage level. 75 Ohm.
We watch the video how to connect a video camera to the monitor.
Free On Top Screen Frame less Webcam Viewer for windows
It is also recommended to look at the passport of the device, especially if the camera has 4 outputs. Most often this means that two double wires will come out of it. Usually yellow is a signal, red is a power supply plus. The remaining two wires can be connected together. However, it is best to carefully read the device passport so as not to break the device.
- press “source” on the remote control;
- select “composite” or “av” mode on the TV screen.
If you connect an ip-camera to a monitor, just a personal computer is enough, a cable (twisted pair) goes from the ip-camera to the computer’s network card (rj45). Install software from the manufacturer’s ip-camera. that’s all. It is not necessary to additionally connect the monitor, since it is already connected to the PC.
Customers often contact us with the question of how to display the image from the DVR on a monitor located at a great distance. For example, it is necessary that the video recorder is in the house, and the monitor is at the checkpoint at the guard. Or another example, when the image needs to be displayed from the DVR at the same time in different rooms.
The simplest thing that comes to mind in such a situation is the use of HDMI extenders over UTP cable. However, the cost of such devices is high when it comes to distances greater than 50 m.Also, you need to remember about scrupulous handling of such devices. in case of an incorrect on-off sequence of circuit nodes using HDMI extenders, their failure or incorrect display on the monitor is possible. In addition, do not forget about the need to use a high-quality UTP 6 cat cable. And I would also like to have camera control, for example, to enlarge the picture, but with this solution you will only have an image.
Let’s consider the case when IP cameras and network video recorder (NVR) are used. The solutions in this situation are simple, due to IP technologies. connect a computer with a client program to the network (for example, iVMS-4500 for Hikvision devices) or use a web browser to display the image. If you do not want to use a computer, then you can install an additional video recorder, to which you also need to add existing IP cameras. It turns out a scheme when both registrars work simultaneously with the same IP cameras, as shown in the figure:
Well, if you use HD-TVI or analog cameras and a video recorder (DVR) Hikvision or HiWatch, then what? you ask. Use an additional recorder and also connect a coaxial cable from each camcorder to it? Not at all. To display images at a long distance on an additional recorder, we can use digital video channels from the first recorder.
Below we will describe in detail how to do this. HiWatch DS-H104G is used as an example of the first recorder, to which three HD-TVI cameras are connected. The additional recorder will be HiWatch DS-H108G. Both registrars are connected to the same IP network. HiWatch DS-H104G recorder has IP address 192.168.1.33.
Go to the settings of the additional HiWatch DS-H108G recorder via the Internet Explorer web browser and go to the System-Controlling Cameras section. Switch three channels to IP mode (uncheck) and save:
Go to the System-Controlling Cameras section and select the “IP Camera” tab and click on the “Add” button.
In the window that appears, indicate the data of the main HiWatch DS-H104G recorder. IP address 192.168.1.33, password and click on the OK button:
In the next window, set the checkboxes on the digital channels that should be added to the additional recorder. In our case, three HD-TVI cameras are used, which are connected to 1-3 channels on the main HiWatch DS-H104G recorder:
Cameras added to additional recorder:
What are the advantages of using an additional video recorder to solve the described problem?
- Cost. An additional recorder will be cheaper than an HDM extension cable (at a distance of more than 50 m);
- Camera control. If you use an extension cord, you will have only an image, and with the help of a video recorder, you can display cameras on the full screen, enlarge the image;
- Simplicity. There is no need to run additional coaxial cable from each HD-TVI camera. You are using the IP functions of Hikvision and HiWatch DVRs.
Webcams are cool. Indeed, there is no limit to what you can do with a webcam. Now the camera may not be as interesting as it used to be, but it is still one of the most useful devices I have. One thing that seems odd to me with webcams is the lack of flexibility in using it.
How can I make sure that I can see on my work what comes from my webcam regardless of what I am doing? What to do if I don’t like to sit in a video chat stupidly and stare at the chat client?
Not so long ago I came across the CamDesk program. This is a tiny open source application that offers a really simple solution to the webcam problems mentioned above. With CamDesk, you can get a constant stream of data from any of your webcams into a customizable window, and you can, no matter what you do, keep an eye on everything that happens in front of the webcam. The program can be used for any purpose: from tracking your cats and watching the front door to constantly broadcasting your image in video chat or recording video. Sumptuously!
How to choose a monitor?
To find the right CCTV monitor for your system and your needs, you need to take into account the following factors:
- monitor matrix resolution;
- diagonal;
- update frequency;
- power;
- external interfaces;
- heat dissipation;
- degree of radiation.
An important feature of the monitor used is that it must have a composite signal input. Without this, connection is impossible.
The most important of these metrics are resolution and diagonal. The first determines how clear the image will be, the second affects the size of the resulting image. The optimal combination is HD resolution (1200×1600 pixels) and diagonal from 18 to 22 inches.
The choice of diagonal is also influenced by the number of video surveillance devices. After all, if there are many cameras, and the screen is small, this simply will not allow you to understand what is happening. According to the existing recommendations, the diagonal depends on the number of video cameras:
- 1-2. 15 inches;
- 3-4. 17 inches;
- 5-9 chambers. 19-22 inches;
- 10-16 cameras. 22-40 inches;
- 17-20 cameras. 32 inches and more.
The clarity and quality of the image depend on the dot pitch. the minimum distance in millimeters between pixels of the same color. The lower this indicator, the clearer the resulting picture will be. Experts strongly advise against buying monitors with a pitch of less than 0.26 mm for monitoring purposes.
The flickering of the screen depends on the refresh rate, and, accordingly, how tired your eyes will be from viewing the picture. You should buy a monitor with a flicker frequency of 85-100 Hz. over, the larger the number, the lower the fatigue.
You also need to pay attention to the connection method. It is recommended to select screens with the maximum number of connection methods (HDMI, VGA, DVI).
If there is always a person in front of the screen watching what is happening, you should choose monitors with less radiation. And for reasons of economy, it is logical to buy a screen with the lowest power consumption.
Since the video surveillance screen is constantly on, you need to take care of overheating or, more precisely, its prevention. For this, it is recommended to purchase a screen with an external power supply. This will reduce the amount of heat inside and increase the lifespan of the device.
On a note! Can be used for video surveillance and the screen of an ordinary home TV. The main thing is that it is equipped with a composite connector via an RCA cable.
CCTV Camera Monitor
For mounting security systems, 2 main types of monitors are used:
- LCD (created using liquid crystals);
- CRT (on a cathode ray tube).
The choice of the monitor is carried out after the purchase of all other devices. Despite the fact that many consider CRT monitors to be obsolete, they can also be effectively used in tandem with cameras. They have their advantages:
- cheapness;
- low screen inertia;
- good display quality of dynamic (moving) objects;
- large viewing angle (up to 180 degrees).
Fans of LCD monitors are also guided by objective reasons:
- compactness;
- low energy consumption;
- lack of flickering in the image;
- high quality color reproduction;
- increased, in comparison with ray screens, image brightness.
Screens on a ray tube usually have a higher resolution (about 1200×1600 pixels), while budget LCD models have fixed lower rates that “eat up” details.
At the same time, LCD monitors have a constant frequency, they do not flicker, which makes them more comfortable for eyesight. They also do not produce radiation harmful to the human body. The same level is achieved only in new more expensive models of CRT screens.
Using CamDesk
If you have more than one webcam connected to your computer, then the first thing you need to do is select the one you want to use to continuously broadcast the video signal. Unfortunately, the camera cannot be changed inside CamDesk, and there is no other option but to restart CamDesk every time you want to change the video source. Since it is a very small and fast application, restarting it shouldn’t cause too many headaches.
Now that you’ve selected a signal source, a video feed should appear on your desktop. It looks something like this:
After combing your hair (which I didn’t seem to be able to do), you can start a video chat or start a video recording, or just browse the web and see yourself at the same time if you want. You can move the video window by dragging it with the mouse and place it in a less visible place on the desktop. Right click on the video to access some additional options.
From the menu that opens, you can start and stop the video, switch to full screen mode, access advanced settings, and stop the CamDesk application. Each operation has its own hotkeys, if you prefer to use them, of course. Let’s see what additional settings are in store for us.
This is Bibi, my old cat, whom I am trying to observe with my other webcam. The advanced settings window, although it looks a little unattractive, offers some useful settings. Here you can dock a video window and make it always on top of other windows, or un-dock and make it behave exactly like other windows. You can also resize the video image and choose it to your liking, and you can also change its transparency.
This last parameter will be interesting if you want to keep an eye on yourself or someone else and do something else at the same time and do not want the video image to cover something of value displayed on the screen. To do this, you can specify that the video image is translucent, and you will not lose sight of it.
If you have an external webcam, you can, no matter what you do on your computer, always keep in sight of the object you are watching. This way I can write this post and watch to see if my cat is awake.
HOT SALE Grade AAA Display For iPhone 5 5S 5C SE LCD Touch Screen Assembly Digitizer Replacement Fu
He’s looking straight at me, isn’t he? As if it is part of the post I am reading.
How to display a WEB-camera on a monitor
CCTV cameras are by far the most effective way to protect your home or place of work from unauthorized entry. Due to the reduction in for analog devices, almost any resident of Russia can afford to install cameras.
The simplest option is to connect a CCTV camera to a monitor. That is easy to do on your own, while allowing you to provide constant supervision of the house, apartment or office. The monitor will display images from all cameras.
In order for the video surveillance system to function correctly and not fail in the first month of operation, you need to make sure that all components are selected and connected correctly.
Installing CamDesk
CamDesk is an open source project that is still being developed by several independent developers. As such, it is magnificent in its simplicity, but only in some places it is incomplete. It is reported that CamDesk is available for Windows, Linux, Chrome and Android systems, but as for the last two implementations, they are still far from the end of the development stage, and even the developers themselves do not recommend downloading them.
If you are using a Linux system, when you download the tar archive, you will find installation instructions in it. With your permission, I will focus on the Windows version for now. To install CamDesk for Windows, you must have the.NET Framework 4 package installed. That’s all you really need to install CamDesk (assuming, of course, you have 1.17 Mb of free space on your hard disk).
CamDesk is portable and there is no installation process as such. Just unzip the files and run the EXE file. You are now ready to try some of the webcam’s features.!
CamDesk is a great little utility that you can use for almost anything you can think of. Here are just a few ideas on what can be done with such a tool. What could you use it for? Do you have great ideas? Share in the comments so we can do it too!
Setting up the device
Users can configure the WEB-camera in OBS-Studio so that the additional window will not only not interfere with the main action. it will perfectly complement the broadcast! Above, we described how to add a new device. as soon as you select a device, an image display will appear on the screen in front of you.
Let’s move on to an important point! Let’s talk about how to crop a WEB-camera in OBS-Studio and move it. we are creating the perfect broadcast screen. The answer is as simple as possible:
- Select the name of the device in the Sources field with the right mouse button;
- The image transmitted from the device is highlighted with a red frame;
- There are handles around the edges. drag on them to move and reduce the size of the source.
In a separate review, we talked about how to set up a WEB-camera in OBS-Studio using an alpha mask (that is, change the shape of the displayed image) or add a frame. We recommend proHonor and use masks / frames to decorate and personalize the stream!
The first step has been taken! The question of how to enable the WEB-camera in OBS should not arise. the image will be transmitted by default if you added the device to the sources.
Let’s go further. let’s talk about what settings should be set for the best, optimal interaction with the program:
- Select the device with the right mouse button and click on the gear. it is located just above and is entitled “Properties”;
- Find the “Resolution / Frame Rate” section and select the “Custom” value;
- In the line “Resolution” we set the numbers corresponding to the technical characteristics of your monitor;
- Select the frame rate. in the line “FPS” you need to set the value “30” from the drop-down menu;
- Look for the “Color Space” icon and select the value “709”;
- Click “OK”. to save your changes.
Now in the same menu we are looking for the “Video Settings” icon. An additional window will appear where you can select brightness, contrast, clarity and saturation. these characteristics are individual, choose according to your monitor.
Do you know how to add and connect a WEB-camera to OBS-Studio. but how to disable it with one click without removing it from the list of sources? Go back to the already familiar properties section and look for the “Deactivate” button! It is located under the name of the device. One click and the camera stops filming.
Instructions for adding a new device
How to make a WEB-camera in OBS-Studio and add your own image to the stream?
- Open the program and select the desired scene in the field of the same name on the left;
- Go to the Sources field and click on the plus sign;
- From the drop-down list select the line “Video capture device”;
- Check the box next to “Create new”. to add a new device;
- Enter the name in the appropriate line and click on the “OK” button.
You got the answer to the main question. but this is not enough! Below we will take a closer look at which settings you should use to get the best quality result.
Why would it even be necessary to add a webcam to OBS? You’ve seen this on streams (for sure). In addition to broadcasting the gameplay, the streamer shows the audience his own face. this is a great way to stay connected and improve interaction with the audience.
How you can add a WEB-camera to OBS-Studio: an up-to-date checklist
How to add a WEB-camera to OBS-Studio and start a game and a conversation with the audience on the stream in parallel? Nothing complicated: follow our step-by-step instructions, everything will work out!
Possible problems
- Open “Device Manager”;
- Open the subsection of the video camera and find the name of the connected or built-in device;
- Make sure the device is actually connected. now you can right-click and select “Update driver”.
The second reason why OBS does not see the WEB-camera and displays a black screen is that the device is busy with another application. See what processes are currently running (you can through the “Task Manager”). If programs that use the WEB-camera are currently open. for example, Skype. close them!
We told in detail how to add and how to enable a WEB-camera in OBS-Studio. be sure to use this tool to establish communication with the audience! Sometimes a voiceover is not enough. and you just need to display a picture on the screen.
How to set up a camera in Zoom
The main use of Zoom is in launching video conferencing with a large number of participants. For everyone to see the user, he must have a connected and properly configured camera. There are almost no problems with this on mobile devices, but problems may arise in the PC program. This article will show you how to set up a camera in Zoom on any device. We will also talk about the “Virtual Background” function. And the last section will describe possible problems with the video and how to solve them.
Virtual background
The “Virtual Background” function replaces the background on the video from the participant’s camera from the familiar environment to any picture or video. It is available both in the mobile application and in the computer program.
This is a very useful feature with a lot of use cases, for example, you can play a conference so that it does not take place in an apartment setting, but on an abandoned beach. In general, a huge number of scenarios.
We have described the details on using the “Virtual Background” function in separate articles:
Mobile devices
There are no camera settings as such in the Android and iOS app. But there are some useful options, such as mute video when joining a conference. To get to this parameter will come out like this:
- Open the mobile version of Zoom on your smartphone or tablet.
- Tap on the points indicated:
- Here activate the slider “Always turn off.”.
In the video conference itself, you can return the picture by clicking on the corresponding icon:
And to change the display from the front camera to the back one, tap on the characteristic icon in the upper left corner:
Manual
First, we need to get to the options page. The easiest way to do this is when the user is logged into an account on the computer:
- Click on the icon next to the “Search” field.
- A context menu will appear. In it, click on the highlighted item:
If authorization has not yet been passed, then this method will not work. But there are two others:
- For Windows. open Zoom, then expand the contents of the system tray, right-click on the characteristic blue and white icon and select “Settings.”.
- For Mac OS or Linux. first connect to any conference, for example, to a test one, and then click on the specified items.
Now visit the section “Video”. In it we are interested in the following options:
- “Camera”. select an input device. You need to make sure that the video from the webcam is shown in the window above. Slightly below the aspect ratio is set. the original or 16: 9 (part of the picture will be cropped).
- “Enable HD mode”. increase the image quality. This requires a higher internet speed.
- “Reflect my.”. a mirror image of the picture.
- “Correct my.”. a special option for processing a person in the frame. Various filters are used, etc.
- “Turn off my.”. when you enter the conference, the webcam will be hidden. You will need to enable it manually.
If the picture in the preview window is displayed incorrectly, then try to rotate it using the corresponding button in the upper right corner:
Solution of problems
Even when everything is configured correctly, the video may not be output. This applies to both PCs and mobile devices. First of all, you should check if another program is currently using the camera. If this is true, then it should be closed for the duration of the videoconference.
The next point only applies to the application for smartphones and tablets. Until you enable access to the camera in Zoom, it will not work. In general, this is done at the stage of installing the application, during the first launch, or when connecting to an online meeting.
But on iPhone and iPad, additional steps may be needed:
- Open system preferences.
- Visit the section “Confidentiality”.
- Next, go to “Camera”.
- Find Zoom at the bottom of the list of apps.
- Enable the corresponding slider if disabled.
- Close the options page.
As a last resort for mobile devices, uninstall and reinstall the Zoom app. Here are links to related instructions:
Full list
Let’s figure out what basic objects we need to display the image from the camera on the screen. There are three of them: Camera, SurfaceView, SurfaceHolder.
Camera is used to get an image from a camera. And in order to display this image in the application, we will use SurfaceView.
I could not find a normal translation of the word Surface. “Surface”. somehow too abstract. Therefore, I will call it. surface. This will mean a certain component that displays the image from the camera.
Work with surface is not carried out directly, but through an intermediary. SurfaceHolder (hereinafter referred to as holder). It is with this object that Camera can work. Also, holder will notify us when the surface is ready for use, changed or no longer available.
To summarize, then: Camera takes the holder and with its help displays the image on the surface.
Let’s write an application in which we implement the output of the image from the camera to the screen.
Project name: P1321_CameraScreen
Build Target: Android 2.3.3
Application name: CameraScreen
Package name: ru.startAndroid.develop.p1321camerascreen
Create Activity: MainActivity
Add rights to the camera in the manifest:
In onCreate, we configure the Activity so that it has no title and full screen. Then we define surface, get its holder and set its type = SURFACE_TYPE_PUSH_BUFFERS (type setting is only needed in Android version below 3.0).
Next, for the holder, we create a HolderCallback callback object (about it a little further), through which the holder will inform us about the states of the surface.
In onResume, we access the camera using the open method. We send the camera ID to the input, if there are several of them (back and front). This method is available from API level 9. At the end of this tutorial there is info on how to get the camera ID.
There is also an open method without requiring an ID to enter. It will give access to the rear camera. It is available in earlier versions too.
After that, we call the setPreviewSize method, in which we set the size of the surface. We will discuss it in detail below.
In onPause, we release the camera using the release method so that other applications can use it.
HolderCallback class that implements the SurfaceHolder.Callback interface. Let me remind you that through it holder informs us about the state of the surface.
surfaceCreated. The surface has been created. We can give the camera a holder object using the setPreviewDisplay method and start broadcasting the image using the startPreview method.
surfaceChanged. The format or size of surface has been changed. In this case, we stop the preview (stopPreview), adjust the camera taking into account the device rotation (setCameraDisplayOrientation, details below), and start the preview again.
surfaceDestroyed. surface is no longer available. Don’t use this method.
There is one oddity with these methods, by the way. The help to the surfaceChanged method says that it will definitely be called not only when changing, but also when creating the surface, i.e. right after surfaceCreated. But at the same time, in the help to the camera, the view start methods (setPreviewDisplay, startPreview) are called both in surfaceCreated and in surfaceChanged. Those. When creating a surface, for some reason we start viewing twice. It is not clear to me why this duplication is needed.
If you clear the surfaceCreated method, everything continues to work. But in the lesson, I probably will not dare to do so. Suddenly I do not understand what and there is some sense in it. If anyone knows. write on the forum.
Rotate preview
If the brain is not already destroyed, now we will fix it! Parse the setCameraDisplayOrientation method, which will rotate the preview.
Let’s look at the example again, when the tablet is used in a horizontal state with the camera on the back. Let’s say we look at the following object through the camera:
Important note. The example described below will not be reproduced through the standard camera application. the standard application handles device rotation. And I want to demonstrate what would have happened if it had not processed.
I rotate the tablet clockwise (to the right) 90 degrees. At the same time, of course, the camera also rotates. Now I see the following picture on the screen:
By the way, you will see the same picture if you tilt your head 90 degrees to the right)
Those. Although the system reacted to the rotation and rotated the main image, the camera returns us exactly this rotated view. We see him.
What should be done to fix this? Rotate the picture 90 clockwise. Those. make the same turn as the camera made.
It turned out the Axiom of Camera Rotation: how much and in which direction the camera is turned, we need to rotate and preview by the same amount and in the same direction in order to get the correct picture.
For this we will use the setDisplayOrientation method. It accepts an angle at the entrance, by which the camera will rotate clockwise before giving it to us. Those. we are expected to rotate the preview clockwise. We can recognize it by finding out how much the camera is turned clockwise (see the Axiom of Camera Rotation).
For this we use the following construction. getWindowManager.getDefaultDisplay.getRotation. It returns us the degrees by which the system rotates the image clockwise so that it is displayed normally when the device is rotated.
Those. when you tilt the device 90 counterclockwise, the system must rotate the image 90 clockwise to compensate for the rotation. (now we are not talking about the camera, but simply about the image that the phone shows, for example. Home)
Axiom of Device Rotation: how much and in which direction the device is turned, by the same amount, but in the other direction, the system rotates the image in order to get it in the correct orientation.
It follows that getWindowManager.getDefaultDisplay.getRotation tells us how much the device is rotated counterclockwise.
By the way, we get constants from getRotation, and then in the switch we convert them to degrees.
So the variable degrees contains the number of degrees the device is rotated counterclockwise.
Is the brain still intact? Then keep this fact: the camera in the device can be rotated relative to this device.
This is usually done on smartphones. Those. there the camera is rotated 90 degrees. And its normal orientation is the same as the horizontal orientation of the device. So that both in the preview and on the screen, the width is greater than the height.
And we also need to take this turn into account when turning the preview. You can get camera data using the getCameraInfo method. The input requires the camera ID and the CameraInfo object, in which the information about the camera will be placed.
We are interested in the CameraInfo.orientation field, which returns how much clockwise the preview should be rotated to get a normal image. Those. based on the Axiom of Camera Rotation. the camera itself is rotated by the same amount.
Well, we finish off the brain with the following fact. The camera can be back and front (front). And for them, turns must be counted in different ways)
CameraInfo.facing field contains info about which camera is rear or front.
Let’s try to count. Let me remind you that the setDisplayOrientation method expects from us the degree of rotation of the preview clockwise. Those. we can simply calculate the clockwise rotation of the camera (Camera Rotation Axiom) and get the desired value.
To find out the final clockwise rotation of the camera in space, add the clockwise rotation of the device and CameraInfo.orientation. This is for the rear camera. And for the front. you need CameraInfo.orientation you Honor, because it looks in our direction. And everything that is clockwise for us is for her. vs.
That’s all, we consider. We have degrees. the number of degrees the device is rotated counterclockwise. To convert this number to degrees clockwise, you just need to Honor them from 360.
Those. (360. degrees) is the clockwise rotation of the device. I deliberately highlighted this expression in parentheses in the code for clarity. Next, we add or subtract to this value (rear or front camera) the built-in camera rotation. In the case of the front camera, just in case we add 360 degrees so that we don’t get a negative number. And at the end, we determine the total number of degrees in the range from 0 to 360, calculating the remainder of dividing by 360.
And we solemnly transfer this meaning to the camera.
An extremely mind-blowing thing. working with a camera, right? As a result, when you start all this, you should see an adequate image from the camera.
At the beginning of the code, there are two constants: CAMERA_ID and FULL_SCREEN.
If you have two cameras, you can transfer not 0, but 1 to CAMERA_ID, and get a picture from the front camera.
Well, by changing FULL_SCREEN, change the view of the preview.
Preview size
SetPreviewSize method. A bit nontrivial, especially if you’ve never worked with Matrix and RectF objects.
In it, we determine the dimensions of the surface, taking into account the screen and the image from the camera, so that the picture is displayed with the correct aspect ratio and full screen.
You can skip further calculations if you are reluctant to break the brain and delve into the mechanism. Although I tried to make these calculations understandable, interesting, and even drew pictures. If you understand everything, it will be great!) Someday this knowledge will come in handy.
So, we have a picture that comes from the camera. let’s call it a preview. And we have a screen on which we need to display this preview.
Let’s consider a specific example to make it clearer. Galaxy Tab, rear camera, normal horizontal position.
There is a screen. Size: 1280×752. Aspect ratio: 1280/752 = 1.70
There is a preview. Size: 640×480. Aspect ratio: 640/480 = 1.33.
Let’s say that we pointed the camera at a circle.
We want to get a full screen image. What are the options? There are three.
1) Stretch the preview to the screen. Bad option, because for this, the aspect ratio must be the same, but we have it different. But still we will try to see the result.
To do this, we need to multiply the preview width by 1280/640 = 2. And the height by 752/480 = 1.57. As a result, we have:
you can see that the picture has become deformed and stretched horizontally. It doesn’t suit us.
2) Squeeze the preview into the screen while maintaining the aspect ratio. To do this, we will resize the preview (keeping the aspect ratio) until it rests against the screen borders in height or width from the inside. In our case, it will rest against the height.
To do this, we need to multiply the width and height of the preview by the smaller of the numbers: 1280/640 = 2 and 752/480 = 1.57, i.e. by 1.57.
it got much better. Now the preview picture is not distorted. The only thing that is a little confusing is the blank areas on the sides of the screen. But nothing prevents to paint them black and let everyone think that this is what was intended. But we will see a complete and undistorted picture. This, for example, is usually done in video players.
3) Squeeze the screen into the preview. Those. make the second option the other way around. Resize the screen (keeping the aspect ratio) until it rests on the inside of the preview border in height or width.
To do this, we would have to divide the width and height of the screen by the larger of the numbers: 1280/640 = 2 and 752/480 = 1.57, i.e. on 2.
But since we cannot physically resize the screen, then we will resize the preview to achieve the described result.
To do this, we need to multiply the width and height of the preview by the larger of the numbers: 1280/640 = 2 and 752/480 = 1.57, i.e. on 2.
The picture is not distorted and occupies the full screen. But there is a nuance. We do not see the entire image. It goes beyond the boundaries of the screen at the top and bottom.
Just in case, I will point out that this is just one example. In others, it may be different. For example, in the second option, empty areas may not be on the sides, but above and below. And on small devices, the preview size will be larger than the screen size. But the general meaning and algorithm do not change from this.
We looked at three options, and saw that the first is very bad, and the second and third are quite suitable for implementation.
From the pictures back to the code. The setPreviewSize (boolean fullScreen) method implements the second (if fullScreen is false) and third (if fullScreen is true) options.
The beauty of the method is that the Matrix does all the transformations for us. And we ourselves will not need to multiply or divide anything.
First, we get the screen size and preview. For the screen, we immediately find out which is larger: width or height. Those. if the width is greater, then the device is in a horizontal orientation, if the height is greater, in a vertical orientation.
For transformations, the matrix will require RectF objects from us. If you have never worked with them, then this is just an object that contains the coordinates of the rectangle: left, top, right, bottom.
We will always use 0 for the left and top, and the width and height of the screen or preview in the right and bottom. Thus, we will get rectangles exactly the same size as the screen and preview.
rectDisplay. screen, rectPreview. preview. The preview is usually always wider than the height. If the device is in horizontal orientation, then we create a rectPreview according to its dimensions. And if the device is vertical, then the image from the camera will also be rotated vertically, therefore the width and height will change places.
Now the fun part is preparing the transformation. We use the setRectToRect method. It takes two RectFs as input. And he calculates what transformations need to be done in order to squeeze the first into the second. I will not talk about the third parameter of the method now, we always use START. (If you are still interested, ask a question on the forum, we will discuss it there)
Those. this method does not change objects yet. This is just a matrix setup. Now the matrix knows what calculations it will need to make with the coordinates of the object, which we will later provide to it.
We look at the code. If (! FullScreen), then this is the second option, i.e. The preview will be squeezed into the screen. To do this, we simply tell the matrix that we need to squeeze the preview-sized object into the screen-sized object. Those. if we turn to the second option, then the matrix realized that it would need to multiply the sides of the object by 1.57. And when we then provide her with an object with the dimensions of the preview, she will do it and we will get the dimensions we need.
If fullScreen (third option), then the algorithm is a little more complicated. We tell the matrix that we need to squeeze the object with the dimensions of the screen into the object with the dimensions of the preview. We look at the third option. At first, we figured out that the screen would need to be divided in two. But then we realized that we cannot change the size of the screen and we need to do the opposite. not divide the screen by two, but multiply the preview by two. We can explain this to the matrix by calling the invert method. The matrix will take the algorithm from the matrix passed to it (i.e. from itself), and will do the opposite. Those. instead of dividing by two, it will multiply.
I really hope that I made it clear. If it is not clear, re-read it 5 times and check with the description of the options and the pictures in the example above. If it’s still not clear, come back to this thread in a week. By that time, the brain has already assimilated and somehow put this information down. And re-reading it can be much easier. At least for me this is usually the case) I can do something about Honor. I don’t understand anything. But after a week / month / half a year to look there again and be surprised: “what was actually incomprehensible here?”
So, we have prepared the matrix for transformation, it remains only to give it an object that it will subject to this transformation. To do this, we use the mapRect method and pass it an object with the size of the preview. As in the example above, we will carry out all the transformations with it.
After carrying out the transformations, we take the resulting coordinates and adjust the surface according to them, which displays the preview.
Other
How can I tell if my device has a camera? This will be reported by context.getPackageManager.hasSystemFeature (PackageManager.FEATURE_CAMERA)
You can get the camera ID using the getNumberOfCameras method (available since API Level 9). It will return us a certain number of cameras N that are available on the device. Accordingly, their IDs will be 0, 1., N-1. By this ID, you already receive CameraInfo and determine what kind of camera it is.
The open method may return an Exception on startup if, for some reason, it was not possible to access the camera. It makes sense to process this and send a message to the user, and not crash with an error.
Rotation handling may not work well on some devices. For example, I tested it on HTC Desire (4.2.2) and Samsung Galaxy Tab (4.2.2). everything was ok. And on Samsung Galaxy Ace (2.3.6) there was a feeling that the camera simply ignores the degree of rotation that I tell it.