Skip to content

Commit

Permalink
Changes to support script and utility to allow for static compilation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwlodek committed Aug 17, 2020
1 parent cdd0ea9 commit ad879aa
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 33 deletions.
35 changes: 22 additions & 13 deletions uvcSupport/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,46 @@

#### Dependencies:

Libuvc depends on libusb.1.*, which can be installed from your linux distribution, or from
Libuvc depends on libusb.1.0, which can be installed from your linux distribution, or from
source.

```
sudo apt install libusb.1.0
sudo apt install libusb-dev
```

#### Installation:

Provided is a script that can be used for easily installing libuvc on a debain based machine.
Provided is a script that can be used for easily installing libuvc on a linux.

```
bash installlibuvc.sh
./install-libuvc.sh
```

It clones the github repository containing the library, runs cmake, and installs the libs into the
appropriate folder. Once this script has been run, simply compile the driver from the top level
It clones the github repository containing the library, runs cmake, and installs the include files and built libraries into the
appropriate folders. Once this script has been run, simply compile the driver from the top level
ADUVC directory.

Optionally, you may also edit the script to uncomment the `sudo make install` command, which will install
libuvc to a system location.

#### Additional tools:

Also included in this directory is a folder titled cameraDetector.
Within this directory is a helper .cpp file that contains code for discovering UVC devices connected
to the specific machine.
This directory contains two additional simple tools for helping with setting up your ADUVC IOC.

For both, you will need to install libuvc with the script as described above. See the README files
in the appropriate directories for more details.

The first utility is a camera detector program, which is used to find supported operating modes
and connection attributes for cameras. The second is a simple program that tests image acquisition using
libuvc and OpenCV for a specified camera.

Before creating an IOC for the device, use the camera detector program to find the following
information that will be required for the configuration later on.

The README.md file in said directory contains information on compiling and running the tool.
Make sure to first install libuvc and then run the tool, prior to booting the IOC,
as there are several values that must be passed to the IOC in the configuration.

These include:

* Serial Number (really a const char*)
* Serial Number
* Framerate
* Resolution (X and Y)
* Video Format
Expand Down
2 changes: 1 addition & 1 deletion uvcSupport/cameraDetector/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all:
g++ uvc_locater.cpp -o uvc_locater -luvc
g++ -I../include -L../os/linux-x86_64 uvc_locater.cpp -o uvc_locater ../os/linux-x86_64/libuvc.a -lusb-1.0 -lpthread
clean:
rm uvc_locater
37 changes: 29 additions & 8 deletions uvcSupport/cameraDetector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,75 @@ critical information about them.

#### Compilation:

To compile the helper program, switch to a root account, and compile using:
To compile this helper program, you must first compile libuvc. The easiest way to do this is to use the
installation script in the `uvcSupport` directory:

```
sudo su
make
./install-libuvc.sh
```

**NOTE:** make sure that libuvc is in your library path. if you used the script in
adUVCSupport to install it, it should have been placed there automatically.
This should use CMake to compile the library, and copy the necessary build artefacts into the correct
locations for compilation.

Once this completes successfully, you can compile the program by just running:

```
make
```

**NOTE:** This will link against pthread, libusb-1.0. You must have these installed to
compile libuvc, along with these helper programs.

#### Usage:

To use the helper, run it as root. These are the possible commands:
To use the locater, you can run it with these possible commands:

```
./uvc_locater -h
```

OR

```
./uvc_locater --help
```

will list some help information about the helper program.


```
./uvc_locater
```

will list all of the uvc devices connected to the machine, and some basic properties.
will list all of the uvc devices connected to the machine, and some basic properties. Certain properties
are locked behind root access, and so will require running the program as root.

From here, you can get a UVC camera's serial number, which can be used in the following way:

```
./uvc_locater -s $SERIAL_NUMBER
```

OR

```
./uvc_locater --serial $SERIAL_NUMBER
```

This will print out detailed information about the camera, including supported video
formats, framerates, and resolutions, all of which must be used in the st.cmd ioc
startup script.

```
./uvc_locater -p $PRODUCT_ID
```

OR

```
./uvc_locater --product $PRODUCT_ID
```

This will print the same information as the search by serial, but will search by product ID.

#### Finding supported data types:
Expand All @@ -64,4 +85,4 @@ This will print the same information as the search by serial, but will search by
Some pointers for finding supported data types:

* Run the locater in detailed mode on the specific camera. Supported frame formats will be listed as Uncompressed or MJPEG
* For Uncompressed formats, look at the 'GUID' field, and this will tell you which format is used for uncompressed. (Y16 -> Gray16, YUY2 -> YUYV, etc.)
* For Uncompressed formats, look at the 'GUID' field, and this will tell you which format is used for uncompressed. (Y16 -> Gray16, YUY2 -> YUYV, etc.)
2 changes: 1 addition & 1 deletion uvcSupport/cameraDetector/uvc_locater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

#include <stdlib.h>
#include <libuvc/libuvc.h>
#include "libuvc/libuvc.h"
#include <stdio.h>
#include <cstddef>
#include <string.h>
Expand Down
22 changes: 17 additions & 5 deletions uvcSupport/imageCaptureTest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@ The program in this directory can be used to test if a connected UVC device can
This program uses openCV to display the image, so it is required to use the program.

Install opencv using:

```
sudo apt install libopencv-dev
```

Once openCV and libuvc have been installed, compile the program as root using
You will also need to install libuvc in order to compile this program. For this, edit the
`install-libuvc.sh` script and uncomment the `sudo make install` line. This will install libuvc
to `/usr/local`. Run the script and libuvc should be installed.

Once openCV and libuvc have been installed, compile the program using:

```
sudo su
make
```

### Usage

First, use the cameraDetector program in the adUVCSupport directory to identify either the serial number or the productID of the camera.
First, use the cameraDetector program in the uvcSupport directory to identify either the serial number or the productID of the camera.

Then, run this program as root in one of the following three ways:

Expand All @@ -30,22 +35,29 @@ Then, run this program as root in one of the following three ways:
```

OR

```
./capture_test -s $SERIAL_NUMBER
```

OR

```
./capture_test -h
```

Note that if product id or serial are hidden behind root access, you may need to run as sudo.

A window will open displaying what the camera can see.
The window will stay open for 200 frames of video an will then close automatically.

You may also specify image dimensions. Run the camera detector in verbose mode to see what formats your camera supports, and then run:
You may also specify image dimensions. Not all dimensions will be supported, make sure your camera
supports whatever image size you input. Run the camera detector in verbose mode to see what formats your camera supports, and then run:

```
./capture_test -p $PRODUCT_ID $XSize $Ysize
```

This will stream in the specified size.

**NOTE** This program only streams in 30 fps, if you would like to stream at a different framerate you will have to edit the source.
**NOTE** This program only streams in 30 fps, and only in the RGB MJPEG format, if you would like to stream at a different framerate you will have to edit the source code.
23 changes: 18 additions & 5 deletions uvcSupport/install-libuvc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
EPICS_HOST_ARCH=linux-x86_64
#EPICS_HOST_ARCH=linux-arm

echo "Building libuvc with expected EPICS target $EPICS_HOST_ARCH..."


if [ -d 'libuvc' ];
then
echo "Removing existing libuvc build artefacts..."
rm -rf libuvc
fi


echo "Grabbing libuvc..."
# Install libuvc by cloning from github and running cmake
git clone https://github.com/jwlodek/libuvc.git
cd libuvc
Expand All @@ -20,7 +31,7 @@ then
rm -rf include
fi


echo "Copying and updating include files..."
# Copy the library include files
cp -r libuvc/include .

Expand All @@ -36,6 +47,9 @@ sed -i "s/#include <libusb.h>/#include <libusb-1.0\/libusb.h>/g" include/libuvc/

# This line will compile the program and place a copy of the libs in /usr/local.
# It is recommended to keep it uncommented to compile the helper programs.
# This is also required if using dynamic linking, and moving the executable.
#
#echo "Installing libuvc to system location..."
#sudo make install


Expand All @@ -47,13 +61,12 @@ then
fi


echo "Copying compiled library files..."
mkdir os
mkdir os/$EPICS_HOST_ARCH
cp libuvc/build/libuvc.a os/$EPICS_HOST_ARCH/.
cp libuvc/build/libuvc.so os/$EPICS_HOST_ARCH/.
cp libuvc/build/libuvc.so.0 os/$EPICS_HOST_ARCH/.
cp libuvc/build/libuvc.so.0.0.6 os/$EPICS_HOST_ARCH/.
cp libuvc/build/libuvc.so* os/$EPICS_HOST_ARCH/.

# Remove build artefacts.
rm -rf libuvc
echo "Finished installing libuvc"
echo "Finished installing libuvc."

0 comments on commit ad879aa

Please sign in to comment.