Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rjdmoore/fictrac into shmem
Browse files Browse the repository at this point in the history
  • Loading branch information
davidt0x committed Jun 28, 2021
2 parents 2b009c1 + 9ac055e commit aae07b1
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 293 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<div align="left">
<img src="http://rjdmoore.net/fictrac/header_text.jpg"><br><br>
</div>
![FicTrac: The webcam-based method for tracking spherical motion and generating fictive animal paths](https://user-images.githubusercontent.com/3844483/110451048-176e9300-80c4-11eb-8e1e-e96545d7d2ed.jpg)

**FicTrac** is an open-source software library for reconstructing the fictive path of an animal walking on a patterned sphere. The software is fast, flexible, easy to use, and simplifies the setup of closed-loop tracking experiments.

Expand Down Expand Up @@ -53,7 +51,7 @@ The FicTrac source code can be built for both Windows and Linux (e.g. Ubuntu) op
2. Linux only:
1. Run the following from terminal to install necessary build tools and dependencies:
```
[Linux] sudo apt-get install gcc g++ git cmake curl unzip tar yasm pkg-config libgtk2.0-dev libavformat-dev libavcodec-dev libavresample-dev libswscale-dev libopencv-dev
sudo apt-get install gcc g++ git cmake curl unzip tar yasm pkg-config libgtk2.0-dev libavformat-dev libavcodec-dev libavresample-dev libswscale-dev libopencv-dev
```
3. (Windows and Linux) Clone or download the [Vcpkg](https://github.com/Microsoft/vcpkg) repository and then follow the guide to install (make sure to perform the bootstrap and integration steps).
4. Using Vcpkg, install remaining dependencies:
Expand Down Expand Up @@ -125,7 +123,7 @@ Before running FicTrac, you may configure your camera (frame rate, resolution, e
<summary>Basler Pylon SDK</summary>
1. Download and install the latest [Pylon SDK](https://www.baslerweb.com/en/products/software/basler-pylon-camera-software-suite/).
2. When preparing the build files for FicTrac using Cmake, you will need to specify to use Pylon using the switch `-D PGR_USB3=ON` and depending on where you installed the SDK, you may also need to provide the SDK directory path using the switch `-D BASLER_DIR=...`. For example, for a Windows installation you would replace step 3 above with (replacing <vcpkg_root> with the path to your vcpkg root directory):
2. When preparing the build files for FicTrac using Cmake, you will need to specify to use Pylon using the switch `-D BASLER_USB3=ON` and depending on where you installed the SDK, you may also need to provide the SDK directory path using the switch `-D BASLER_DIR=...`. For example, for a Windows installation you would replace step 3 above with (replacing <vcpkg_root> with the path to your vcpkg root directory):
```
cmake -A x64 -D CMAKE_TOOLCHAIN_FILE=<vcpkg root>/scripts/buildsystems/vcpkg.cmake -D BASLER_USB3=ON -D BASLER_DIR="C:\path\to\Pylon" ..
```
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# https://docs.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure-devops&tabs=yaml

trigger:
#- master
- develop
- master
#- develop

# We can run multiple jobs in parallel.
# see https://docs.microsoft.com/en-us/azure/devops/pipelines/process/phases
Expand Down
2 changes: 1 addition & 1 deletion doc/params.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ In the table below, the various possible parameters are listed. If nothing is li
| thr_ratio | float | 1.25 | (0,inf) | Only if you need to | Adjusts the adaptive thresholding of the input image. Values > 1 will favour foreground regions (more white in thresholded image) and values < 1 will favour background regions (more black in thresholded image). |
| thr_win_pc | float | 0.2 | \[0,1] | Only if you need to | Adjusts the size of the neighbourhood window to use for adaptive thresholding of the input image, specified as a percentage of the width of the tracking window. Larger values avoid over-segmentation, whilst smaller values make segmentation more robust to illumination gradients on the trackball. |
| vid_codec | string | h264 | [h264,xvid,mpg4,mjpg,raw] | Only if you need to | Specifies the video codec to use when writing output videos (see `save_raw` and `save_debug`). |
| sphere_map_fn | string | | | Only if you need to | If specified, FicTrac will attempt to load a previously generated sphere surface map from this filename. |
| sphere_map_fn | string | | | Only if you need to | If specified, FicTrac will attempt to load a previously generated sphere surface map from this filename. Note that if you set this option, you should probably also set `opt_do_global` otherwise FicTrac may not find the initial sphere attitude. |
| | | | | | |
| opt_max_evals | int | 50 | (0,inf) | Probably not | Specifies the maximum number of minimisation iterations to perform each frame. Smaller values may improve tracking frame rate at the risk of finding sub-optimal matches. Number of optimisation iterations is printed to screen during tracking (its=...). |
| opt_bound | float | 0.35 | (0,inf) | Probably not | Specifies the optimisation search range in radians. Larger values will facilitate more track ball rotation per frame, but result in slower tracking and also possibly lead to false matches. |
Expand Down
5 changes: 0 additions & 5 deletions include/typesvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,3 @@ const CmReal CM_PI = 3.14159265358979323846;
const CmReal CM_PI_2 = 1.57079632679489661923;
const CmReal CM_R2D = 180.0 / CM_PI;
const CmReal CM_D2R = CM_PI / 180.0;

//enum THR_MODE {
// ADAPT,
// NORM_PRIORS
//};
109 changes: 63 additions & 46 deletions scripts/socket_client.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,75 @@
#!/usr/bin/env python3

import socket
import select

HOST = '127.0.0.1' # The (receiving) host IP address (sock_host)
PORT = ???? # The (receiving) host port (sock_port)

# TCP
# Open the connection (ctrl-c / ctrl-break to quit)
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock: # UDP
#with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: # TCP
sock.bind((HOST, PORT)) # UDP
# sock.connect((HOST, PORT)) # TCP

data = ""
#with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
# sock.connect((HOST, PORT))

# UDP
# Open the connection (ctrl-c / ctrl-break to quit)
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
sock.bind((HOST, PORT))
sock.setblocking(0)

# Keep receiving data until FicTrac closes
data = ""
timeout_in_seconds = 1
while True:
# Receive one data frame
new_data = sock.recv(1024)
if not new_data:
break

# Decode received data
data += new_data.decode('UTF-8')

# Find the first frame of data
endline = data.find("\n")
line = data[:endline] # copy first frame
data = data[endline+1:] # delete first frame

# Tokenise
toks = line.split(", ")

# Check that we have sensible tokens
if ((len(toks) < 24) | (toks[0] != "FT")):
print('Bad read')
continue

# Extract FicTrac variables
# (see https://github.com/rjdmoore/fictrac/blob/master/doc/data_header.txt for descriptions)
cnt = int(toks[1])
dr_cam = [float(toks[2]), float(toks[3]), float(toks[4])]
err = float(toks[5])
dr_lab = [float(toks[6]), float(toks[7]), float(toks[8])]
r_cam = [float(toks[9]), float(toks[10]), float(toks[11])]
r_lab = [float(toks[12]), float(toks[13]), float(toks[14])]
posx = float(toks[15])
posy = float(toks[16])
heading = float(toks[17])
step_dir = float(toks[18])
step_mag = float(toks[19])
intx = float(toks[20])
inty = float(toks[21])
ts = float(toks[22])
seq = int(toks[23])
# Check to see whether there is data waiting
ready = select.select([sock], [], [], timeout_in_seconds)

# Only try to receive data if there is data waiting
if ready[0]:
# Receive one data frame
new_data = sock.recv(1024)

# Uh oh?
if not new_data:
break

# Decode received data
data += new_data.decode('UTF-8')

# Find the first frame of data
endline = data.find("\n")
line = data[:endline] # copy first frame
data = data[endline+1:] # delete first frame

# Tokenise
toks = line.split(", ")

# Check that we have sensible tokens
if ((len(toks) < 24) | (toks[0] != "FT")):
print('Bad read')
continue

# Extract FicTrac variables
# (see https://github.com/rjdmoore/fictrac/blob/master/doc/data_header.txt for descriptions)
cnt = int(toks[1])
dr_cam = [float(toks[2]), float(toks[3]), float(toks[4])]
err = float(toks[5])
dr_lab = [float(toks[6]), float(toks[7]), float(toks[8])]
r_cam = [float(toks[9]), float(toks[10]), float(toks[11])]
r_lab = [float(toks[12]), float(toks[13]), float(toks[14])]
posx = float(toks[15])
posy = float(toks[16])
heading = float(toks[17])
step_dir = float(toks[18])
step_mag = float(toks[19])
intx = float(toks[20])
inty = float(toks[21])
ts = float(toks[22])
seq = int(toks[23])

# Do something ...
print(cnt)

# Do something ...
print(cnt)
else:
# Didn't find any data - try again
print('retrying...')
7 changes: 5 additions & 2 deletions src/Trackball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,12 +864,15 @@ void Trackball::updateSphere()
uint8_t& map = _sphere_map.data[py * _sphere_map.step + px];

// update map tile
if (map == 128) {
if ((map == 0) || (map == 255)) {
// map tile frozen
good++;
} else if (map == 128) {
// map tile previously unseen
map = (proi[j] == 255) ? (128 + SPHERE_MAP_FIRST_HIT_BONUS) : (128 - SPHERE_MAP_FIRST_HIT_BONUS);
} else {
good++;
map = min(max((proi[j] == 255) ? (int(map) + 1) : (int(map) - 1), 0), 255);
map = (proi[j] == 255) ? (map + 1) : (map - 1);
}

// display
Expand Down
Binary file removed test/3axis0.avi
Binary file not shown.
22 changes: 0 additions & 22 deletions test/3axis0.cfg

This file was deleted.

100 changes: 0 additions & 100 deletions test/3axis0_gt.csv

This file was deleted.

64 changes: 0 additions & 64 deletions test/test.py

This file was deleted.

Loading

0 comments on commit aae07b1

Please sign in to comment.