Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python_tracker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
swp21_biotracker
python_tracker
Commits
2cd04da1
Commit
2cd04da1
authored
Jun 14, 2022
by
Max Breitenfeldt
Browse files
Options
Downloads
Patches
Plain Diff
Add debug messages
parent
8355c3ef
No related branches found
No related tags found
No related merge requests found
Pipeline
#50371
failed
Jun 14, 2022
Stage: build
Stage: package
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Src/Model/BioTrackerTrackingAlgorithm.cpp
+89
-79
89 additions, 79 deletions
Src/Model/BioTrackerTrackingAlgorithm.cpp
with
89 additions
and
79 deletions
Src/Model/BioTrackerTrackingAlgorithm.cpp
+
89
−
79
View file @
2cd04da1
#include
"BioTrackerTrackingAlgorithm.h"
#include
<errno.h>
#include
<fcntl.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string>
#include
<sys/mman.h>
#include
<sys/stat.h>
#include
<unistd.h>
#include
<iostream>
#include
"BioTrackerTrackingAlgorithm.h"
#include
<future>
#include
"TrackedComponents/pose/FishPose.h"
#include
<chrono>
#include
<future>
#include
<iostream>
#include
<string>
#include
<zmq.hpp>
#include
"TrackedComponents/pose/FishPose.h"
#define JSON_USE_IMPLICIT_CONVERSIONS 0
#include
"json.hpp"
using
json
=
nlohmann
::
json
;
BioTrackerTrackingAlgorithm
::
BioTrackerTrackingAlgorithm
(
IController
*
parent
,
IModel
*
parameter
,
IModel
*
trajectory
)
:
IModelTrackingAlgorithm
(
parent
)
{
BioTrackerTrackingAlgorithm
::
BioTrackerTrackingAlgorithm
(
IController
*
parent
,
IModel
*
parameter
,
IModel
*
trajectory
)
:
IModelTrackingAlgorithm
(
parent
)
{
_cfg
=
static_cast
<
ControllerTrackingAlgorithm
*>
(
parent
)
->
getConfig
();
_TrackingParameter
=
(
TrackerParameter
*
)
parameter
;
_TrackedTrajectoryMajor
=
(
BST
::
TrackedTrajectory
*
)
trajectory
;
...
...
@@ -31,10 +34,7 @@ BioTrackerTrackingAlgorithm::BioTrackerTrackingAlgorithm(IController *parent, IM
_lastFramenumber
=
-
1
;
}
BioTrackerTrackingAlgorithm
::~
BioTrackerTrackingAlgorithm
()
{
stop_python
();
}
BioTrackerTrackingAlgorithm
::~
BioTrackerTrackingAlgorithm
()
{
stop_python
();
}
void
BioTrackerTrackingAlgorithm
::
init_shared_memory
()
{
json
j
=
{
...
...
@@ -53,9 +53,8 @@ void BioTrackerTrackingAlgorithm::init_shared_memory() {
throw
"shm_open"
;
}
void
*
shm_buf
=
mmap
(
NULL
,
shm_len
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
fd
,
0
);
void
*
shm_buf
=
mmap
(
NULL
,
shm_len
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
fd
,
0
);
close
(
fd
);
if
(
shm_buf
==
MAP_FAILED
)
{
...
...
@@ -77,17 +76,21 @@ void BioTrackerTrackingAlgorithm::start_python() {
auto
model_path
=
_TrackingParameter
->
getModelPath
().
toStdString
();
_python_process
=
boost
::
process
::
child
(
boost
::
process
::
search_path
(
"python3"
),
boost
::
process
::
args
({
"-c"
,
"from biotracker import BiotrackerAdapter;"
"BiotrackerAdapter('"
+
model_path
+
"'"
",verbose=True).run();"
}),
_python_process_group
);
boost
::
process
::
args
({
"-c"
,
"from biotracker import BiotrackerAdapter;"
"BiotrackerAdapter('"
+
model_path
+
"'"
",verbose=True).run();"
}),
_python_process_group
);
fprintf
(
stderr
,
"Adapter started
\n
"
);
_sock
=
zmq
::
socket_t
(
_ctx
,
zmq
::
socket_type
::
req
);
_sock
.
connect
(
"ipc:///tmp/biotracker.python.zmq"
);
}
void
BioTrackerTrackingAlgorithm
::
receiveAreaDescriptorUpdate
(
IModelAreaDescriptor
*
areaDescr
)
{
void
BioTrackerTrackingAlgorithm
::
receiveAreaDescriptorUpdate
(
IModelAreaDescriptor
*
areaDescr
)
{
_areaInfo
=
areaDescr
;
}
...
...
@@ -101,8 +104,8 @@ void BioTrackerTrackingAlgorithm::receiveParametersChanged() {
}
}
void
BioTrackerTrackingAlgorithm
::
doTracking
(
std
::
shared_ptr
<
cv
::
Mat
>
p_image
,
uint
framenumber
)
{
void
BioTrackerTrackingAlgorithm
::
doTracking
(
std
::
shared_ptr
<
cv
::
Mat
>
p_image
,
uint
framenumber
)
{
_lastImage
=
p_image
;
_lastFramenumber
=
framenumber
;
...
...
@@ -112,24 +115,29 @@ void BioTrackerTrackingAlgorithm::doTracking(std::shared_ptr<cv::Mat> p_image, u
}
// skip frame if model is not yet loaded
if
(
_python_process
.
has_value
())
{
if
(
!
_python_process
)
{
fprintf
(
stderr
,
"Adapter not running!
\n
"
);
return
;
}
if
(
_imageX
!=
p_image
->
size
().
width
||
_imageY
!=
p_image
->
size
().
height
)
{
_imageX
=
p_image
->
size
().
width
;
_imageY
=
p_image
->
size
().
height
;
fprintf
(
stderr
,
"Initializing shared memory...
\n
"
);
init_shared_memory
();
fprintf
(
stderr
,
"Done
\n
"
);
Q_EMIT
emitDimensionUpdate
(
_imageX
,
_imageY
);
}
// Refuse to run tracking if we have no area info...
if
(
_AreaInfo
==
nullptr
)
{
fprintf
(
stderr
,
"Missing area info
\n
"
);
Q_EMIT
emitTrackingDone
(
framenumber
);
return
;
}
std
::
chrono
::
system_clock
::
time_point
start
=
std
::
chrono
::
system_clock
::
now
();
std
::
chrono
::
system_clock
::
time_point
start
=
std
::
chrono
::
system_clock
::
now
();
cv
::
Mat
grayscale
,
float_img
;
cv
::
cvtColor
(
*
p_image
,
grayscale
,
cv
::
COLOR_BGR2GRAY
);
...
...
@@ -148,10 +156,10 @@ void BioTrackerTrackingAlgorithm::doTracking(std::shared_ptr<cv::Mat> p_image, u
std
::
vector
<
std
::
tuple
<
int
,
FishPose
>>
poses
;
for
(
auto
pos
:
msg
[
"data"
])
{
fprintf
(
stderr
,
"Here
\n
"
);
auto
pose
=
std
::
make_tuple
(
pos
[
"id"
].
get
<
int
>
(),
FishPose
(
_areaInfo
,
FishPose
(
_areaInfo
,
cv
::
Point2f
(
pos
[
"x"
].
get
<
int
>
(),
pos
[
"y"
].
get
<
int
>
()),
pos
[
"orientation"
].
get
<
float
>
(),
1.0
));
// FIXME: score
...
...
@@ -165,9 +173,11 @@ void BioTrackerTrackingAlgorithm::doTracking(std::shared_ptr<cv::Mat> p_image, u
// Insert new poses into data structure
int
trajNumber
=
0
;
for
(
int
i
=
0
;
i
<
_TrackedTrajectoryMajor
->
size
();
i
++
)
{
BST
::
TrackedTrajectory
*
t
=
dynamic_cast
<
BST
::
TrackedTrajectory
*>
(
_TrackedTrajectoryMajor
->
getChild
(
i
));
BST
::
TrackedTrajectory
*
t
=
dynamic_cast
<
BST
::
TrackedTrajectory
*>
(
_TrackedTrajectoryMajor
->
getChild
(
i
));
if
(
t
&&
t
->
getValid
()
&&
!
t
->
getFixed
())
{
BST
::
TrackedElement
*
e
=
new
BST
::
TrackedElement
(
t
,
"n.a."
,
t
->
getId
());
BST
::
TrackedElement
*
e
=
new
BST
::
TrackedElement
(
t
,
"n.a."
,
t
->
getId
());
e
->
setFishPose
(
std
::
get
<
1
>
(
poses
[
trajNumber
]));
e
->
setTime
(
start
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment