Skip to content

Commit

Permalink
Merge pull request #2 from JuliaRobotics/23Q3/enh/readme
Browse files Browse the repository at this point in the history
readme and ImagesExt
  • Loading branch information
dehann authored Sep 21, 2023
2 parents aa55659 + 57cbcf6 commit effa187
Show file tree
Hide file tree
Showing 10 changed files with 546 additions and 8 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,25 @@ jobs:
julia-version: ['1.9', '~1.10.0-0', 'nightly']
os: [ubuntu-latest]
arch: [x64]
# https://github.com/ros-tooling/action-ros-ci/blob/master/.github/workflows/test.yml
ros_distribution:
- noetic
include:
# Noetic Ninjemys (May 2020 - May 2025)
- docker_image: rostooling/setup-ros-docker:ubuntu-focal-ros-noetic-ros-base-latest
ros_distribution: noetic
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
# with:
# python-version: '3.9'
# cache: 'pip'
# - run: pip install opencv-python
# - uses: ros-tooling/[email protected]
# with:
# required-ros-distributions: noetic
# - run: "source /opt/ros/noetic/setup.bash"
# docker pull osrf/ros:noetic-desktop
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
Expand Down
10 changes: 9 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@ version = "0.1.0"
[deps]
Caesar = "62eebf14-49bc-5f46-9df9-f7b7ef379406"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DistributedFactorGraphs = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
Unmarshal = "cbff2730-442d-58d7-89d1-8e530c41eb02"

[weakdeps]
RobotOS = "22415677-39a4-5241-a37a-00beabbbdae8"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"

[extensions]
PyCaesarRobotOSExt = "RobotOS"
PyCaesarImagesExt = "Images"

[compat]
Caesar = "0.15, 0.16"
Expand All @@ -29,6 +36,7 @@ julia = "1.9"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"

[targets]
test = ["RobotOS", "Test"]
test = ["RobotOS", "Test", "TestImages"]
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# PyCaesar.jl

| Stable | Dev | Coverage | Docs |
|--------|-----|----------|------|
| [![version][pycjl-ver-img]][pycjl-releases] | [![CI][pycjl-ci-dev-img]][pycjl-ci-dev-url] | [![codecov.io][pycjl-cov-img]][pycjl-cov-url] | [![docs][cjl-docs-img]][cjl-docs-url] <br> [![][caesar-slack-badge]][caesar-slack] |

## Dependencies

The following packages should be available in the Python environment used by PyCall.jl

```
rospy
opencv-python # i.e. cv2
open3d
Rosbags
```

> 23Q3: We had issues in using Conda.jl to install these dependecies in a new environment, specifically conda package compliance with newer versions of Python. E.g. open3d was not available via conda on Python 3.10 at the time of writing. Please open an issue if further clarification is needed.
## Introduction

Caesar.jl extensions using Python. See common [Caesar.jl][cjl-docs-url] Docs for details.


[pycjl-url]: http://www.github.com/JuliaRobotics/PyCaesar.jl
[pycjl-cov-img]: https://codecov.io/github/JuliaRobotics/PyCaesar.jl/coverage.svg?branch=develop
[pycjl-cov-url]: https://codecov.io/github/JuliaRobotics/PyCaesar.jl?branch=develop
[pycjl-ci-dev-img]: https://github.com/JuliaRobotics/PyCaesar.jl/actions/workflows/CI.yml/badge.svg
[pycjl-ci-dev-url]: https://github.com/JuliaRobotics/PyCaesar.jl/actions/workflows/CI.yml
[pycjl-ver-img]: https://juliahub.com/docs/PyCaesar/version.svg
[pycjl-milestones]: https://github.com/JuliaRobotics/PyCaesar.jl/milestones
[pycjl-releases]: https://github.com/JuliaRobotics/PyCaesar.jl/releases

[cjl-url]: https://github.com/JuliaRobotics/Caesar.jl
[cjl-docs-img]: https://img.shields.io/badge/docs-latest-blue.svg
[cjl-docs-url]: http://juliarobotics.github.io/Caesar.jl/latest/
[caesar-slack-badge]: https://img.shields.io/badge/Caesarjl-Slack-green.svg?style=popout
[caesar-slack]: https://join.slack.com/t/caesarjl/shared_invite/zt-ucs06bwg-y2tEbddwX1vR18MASnOLsw
38 changes: 38 additions & 0 deletions ext/PyCaesarImagesExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module PyCaesarImagesExt

using PyCall
using Images
# using PyCaesars
# using ImageFeatures
using DistributedFactorGraphs
using ProgressMeter
using JSON3
using TensorCast
using SHA: sha256

import PyCaesar: calcFlow, getPose, goodFeaturesToTrack, goodFeaturesToTrackORB, combinePlot
import PyCaesar: trackFeaturesFrames, trackFeaturesForwardsBackwards, makeBlobFeatureTracksPerImage_FwdBck!, makeORBParams, plotBlobsImageTracks!
import PyCaesar: whatcv

export calcFlow, getPose, goodFeaturesToTrack, goodFeaturesToTrackORB, combinePlot
export trackFeaturesFrames, trackFeaturesForwardsBackwards, makeBlobFeatureTracksPerImage_FwdBck!, makeORBParams, plotBlobsImageTracks!


const np = PyNULL()
const cv = PyNULL()

function __init__()
copy!(np, pyimport("numpy"))
copy!(cv, pyimport("cv2"))
end

pyutilpath = joinpath(@__DIR__, "Utils")
pushfirst!(PyVector(pyimport("sys")."path"), pyutilpath )

SscPy = pyimport("PySSCFeatures")
ssc = SscPy."ssc"


include("services/OpenCVFeatures.jl")

end
131 changes: 131 additions & 0 deletions ext/Utils/PySSCFeatures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Taken from: https://github.com/BAILOOL/ANMS-Codes/blob/568fa6a1b39aa46fa04ad600cb40a33decf52897/Python/ssc.py#L1

# @article{bailo2018efficient,
# title={Efficient adaptive non-maximal suppression algorithms for homogeneous spatial keypoint distribution},
# author={Bailo, Oleksandr and Rameau, Francois and Joo, Kyungdon and Park, Jinsun and Bogdan, Oleksandr and Kweon, In So},
# journal={Pattern Recognition Letters},
# volume={106},
# pages={53--60},
# year={2018},
# publisher={Elsevier}
# }

# MIT "Expat" License

# Copyright (c) 2018 Oleksandr Bailo

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


import math

def ssc(keypoints, num_ret_points, tolerance, cols, rows):
exp1 = rows + cols + 2 * num_ret_points
exp2 = (
4 * cols
+ 4 * num_ret_points
+ 4 * rows * num_ret_points
+ rows * rows
+ cols * cols
- 2 * rows * cols
+ 4 * rows * cols * num_ret_points
)
exp3 = math.sqrt(exp2)
exp4 = num_ret_points - 1

sol1 = -round(float(exp1 + exp3) / exp4) # first solution
sol2 = -round(float(exp1 - exp3) / exp4) # second solution

high = (
sol1 if (sol1 > sol2) else sol2
) # binary search range initialization with positive solution
low = math.floor(math.sqrt(len(keypoints) / num_ret_points))

prev_width = -1
selected_keypoints = []
result_list = []
result = []
complete = False
k = num_ret_points
k_min = round(k - (k * tolerance))
k_max = round(k + (k * tolerance))

while not complete:
width = low + (high - low) / 2
if (
width == prev_width or low > high
): # needed to reassure the same radius is not repeated again
result_list = result # return the keypoints from the previous iteration
break

c = width / 2 # initializing Grid
num_cell_cols = int(math.floor(cols / c))
num_cell_rows = int(math.floor(rows / c))
covered_vec = [
[False for _ in range(num_cell_cols + 1)] for _ in range(num_cell_rows + 1)
]
result = []

for i in range(len(keypoints)):
row = int(
math.floor(keypoints[i].pt[1] / c)
) # get position of the cell current point is located at
col = int(math.floor(keypoints[i].pt[0] / c))
if not covered_vec[row][col]: # if the cell is not covered
result.append(i)
# get range which current radius is covering
row_min = int(
(row - math.floor(width / c))
if ((row - math.floor(width / c)) >= 0)
else 0
)
row_max = int(
(row + math.floor(width / c))
if ((row + math.floor(width / c)) <= num_cell_rows)
else num_cell_rows
)
col_min = int(
(col - math.floor(width / c))
if ((col - math.floor(width / c)) >= 0)
else 0
)
col_max = int(
(col + math.floor(width / c))
if ((col + math.floor(width / c)) <= num_cell_cols)
else num_cell_cols
)
for row_to_cover in range(row_min, row_max + 1):
for col_to_cover in range(col_min, col_max + 1):
if not covered_vec[row_to_cover][col_to_cover]:
# cover cells within the square bounding box with width w
covered_vec[row_to_cover][col_to_cover] = True

if k_min <= len(result) <= k_max: # solution found
result_list = result
complete = True
elif len(result) < k_min:
high = width - 1 # update binary search range
else:
low = width + 1
prev_width = width

for i in range(len(result_list)):
selected_keypoints.append(keypoints[result_list[i]])

return selected_keypoints
10 changes: 5 additions & 5 deletions ext/Utils/RosbagSubscriber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ writeRosbagPy = pyimport("rosbagWriter")
```julia
# Link with ROSbag infrastructure via rospy
using Pkg
ENV["PYTHON"] = "/usr/bin/python3"
Pkg.build("PyCall")
using PyCall
# using Pkg
# ENV["PYTHON"] = "/usr/bin/python3"
# Pkg.build("PyCall")
# using PyCall
using RobotOS
@rosimport std_msgs.msg: String
rostypegen()
rostypegen(Main) # default defintion dump into Main
using Caesar
bagwr = Caesar.RosbagWriter("/tmp/test.bag")
Expand Down
Loading

0 comments on commit effa187

Please sign in to comment.