Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STR ISS Image Detector #98

Merged
merged 99 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
096a006
Added images
rachlu Jun 9, 2023
54eecbd
Added CRAFT and parseq libraries
Jun 12, 2023
ccabba9
Made parse text file
Jun 12, 2023
60837d9
Merged CRAFT and parseq
Jun 12, 2023
cd08b9f
Added decoding for each boundary box found
Jun 13, 2023
55b39bd
Added tests for other ocr libraries
Jun 14, 2023
3fbbe76
infrastructure work on docker processes
marinagmoreira Jun 14, 2023
c16ca20
Testing on various images
Jun 14, 2023
31e6822
making ci pr use the build script
marinagmoreira Jun 15, 2023
7aac089
analyst notebook now depends on entire isaac for python packages
marinagmoreira Jun 15, 2023
f4e7712
fixing astrobee path
marinagmoreira Jun 15, 2023
4a04f86
sintax + analyst only in ubuntu 20
marinagmoreira Jun 15, 2023
96d9abc
Edited image cropping
Jun 15, 2023
a6ab177
Merge branch 'analyst_docker_compose' of github.com:marinagmoreira/is…
Jun 15, 2023
7f561a6
Added database and label finder
Jun 16, 2023
74c9076
Label detection
Jun 20, 2023
02b0f3e
Trade Study results
Jun 20, 2023
bc6f9c8
Fixed imports
Jun 21, 2023
ce7b39b
Phrase detection wn working
Jun 21, 2023
ae98f38
Fixed git submodules
Jun 21, 2023
15d44de
Fixed imports
Jun 21, 2023
4ec8a0d
Jupyter Notebook outline
Jun 21, 2023
dc06da0
Organization
Jun 21, 2023
53c6463
Jupyter Notebook OCR implementation
Jun 21, 2023
062f926
Working on imports
Jun 22, 2023
cc3d693
Made image str into Python package
Jun 23, 2023
3f56d6c
Image_str Python Package
Jun 23, 2023
f91661c
Merge branch 'develop' of github.com:nasa/isaac into test
marinagmoreira Jun 27, 2023
9da68a1
Optimizing parser
Jun 27, 2023
89b7955
Formatting
Jun 27, 2023
58a2d6e
organizing stuff
marinagmoreira Jun 27, 2023
4e76d50
Merge branch 'test' into opt
marinagmoreira Jun 27, 2023
be5853b
adding some str dependencies
marinagmoreira Jun 27, 2023
f542eb9
Imports for Analyst Notebook
Jun 27, 2023
e5e5540
Analyst Test
Jun 27, 2023
c06e15e
Edited image slicing and similarity parameters
Jun 28, 2023
10d119c
Formatting
Jun 28, 2023
2578dc7
Removed craft and parseq
Jun 28, 2023
dcabdaa
Removed folders
Jun 28, 2023
2749268
removed folders
Jun 28, 2023
fd6f134
Added folders to gitignore
Jun 28, 2023
6fe8226
Jupyter Notebook display
Jun 28, 2023
1dcdd37
Working Analyst demo
Jun 29, 2023
f85b770
Fixed overlapping boundary boxes
Jun 30, 2023
ae6e8f3
Removed images folder
Jun 30, 2023
aa400e7
Organization
Jun 30, 2023
ebbed61
Starting 3D location
Jun 30, 2023
1335c0c
Getting 3D position
Jul 5, 2023
065212b
Parsing 3D output
rachlu Jul 5, 2023
4da8425
Removed data.json
rachlu Jul 6, 2023
4b7183e
Added graphing for 3D positions of labels
rachlu Jul 6, 2023
afa5b5f
Graphing of 3D positions of labels
rachlu Jul 6, 2023
f167c28
Graph display
Jul 7, 2023
48c3824
Stored data in .dat file
rachlu Jul 10, 2023
b2bf906
Label .dat file and duplication removal
rachlu Jul 11, 2023
3c83381
Refactored to account for 3D locations
rachlu Jul 13, 2023
a19e760
save results to csv file
rachlu Jul 14, 2023
e1baede
Finding 3D locations
rachlu Jul 14, 2023
ec84b3b
Working Jupyter Notebook demo
rachlu Jul 20, 2023
3aab363
Removed changes in docker
rachlu Jul 20, 2023
69e66ca
Created panorama link
rachlu Jul 20, 2023
7fbc3d1
Started documentation and added bumble data
rachlu Jul 21, 2023
fb0f6c2
Documentation
rachlu Jul 21, 2023
ffe200a
Changed image to RGB and fixed find
rachlu Jul 24, 2023
d04c739
Changed how to detect duplicates
rachlu Jul 24, 2023
b63e195
Refactored code into a class
rachlu Jul 25, 2023
4ebb1ad
Changed find result display
rachlu Jul 26, 2023
0b9bda6
Adding interactive graph
rachlu Jul 27, 2023
07e9914
New visualization and craft model download
rachlu Jul 28, 2023
92e6f68
Removed models
rachlu Jul 31, 2023
9733d7c
Removed test folders
rachlu Jul 31, 2023
f3eee38
Fixed display
rachlu Jul 31, 2023
f254eb9
Cleaned up code and documentation
rachlu Aug 2, 2023
6430f89
Finished Documentation
rachlu Aug 2, 2023
2c80bea
Added display for running locally
rachlu Aug 2, 2023
82d22ea
Speed up find label
rachlu Aug 3, 2023
e53c158
Added Documentation
rachlu Aug 8, 2023
81df7b9
Edited Readme
rachlu Aug 8, 2023
c7bc669
Documentation edits
rachlu Aug 8, 2023
f3407ce
Edited imports on Analyst Notebook
rachlu Aug 8, 2023
0fe7d5e
Merge branch 'develop' into opt
marinagmoreira Oct 26, 2023
3f4c5c4
Merge branch 'develop' of github.com:nasa/isaac into opt
marinagmoreira Mar 18, 2024
dc1bfa9
Merge branch 'opt' of github.com:rachlu/isaac into opt
marinagmoreira Mar 18, 2024
3787701
making packages independent from img_str; standardized python package
marinagmoreira Mar 22, 2024
71dcb9e
removing submodule from gitmodules
marinagmoreira Mar 25, 2024
98431a6
fix dependencies
marinagmoreira Mar 25, 2024
98f5fe0
scikit soen't seem to exist, replacing it with scikit-image since it'…
marinagmoreira Mar 25, 2024
0d47676
Merge branch 'develop' of github.com:nasa/isaac into opt
marinagmoreira Mar 28, 2024
c635f4c
deleting result files
marinagmoreira Mar 31, 2024
c447879
simplify cmake
marinagmoreira Mar 31, 2024
7548711
no nodelet plugins in this package
marinagmoreira Mar 31, 2024
3f72322
fixing CI hierarchy
marinagmoreira Mar 31, 2024
27d8cc1
Merge branch 'develop' of github.com:nasa/isaac into opt
marinagmoreira Apr 4, 2024
4c650fb
docker compose version obsolete; fixes on name changes
marinagmoreira Apr 4, 2024
dc70f3c
adding model compatible with focal
marinagmoreira Apr 6, 2024
686b0f5
generilizing the code + removing specific paths
marinagmoreira Apr 7, 2024
02b2f40
env vars check fix
marinagmoreira Apr 9, 2024
5c9670c
making folder consistent; still showing results if no bagfile
marinagmoreira Apr 9, 2024
9895ccf
Merge branch 'develop' of github.com:nasa/isaac into opt
marinagmoreira Apr 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ analyst/workspace/.ipython
analyst/workspace/.jupyter
analyst/workspace/.local
analyst/workspace/.ipynb_checkpoints
analyst/workspace/results
analyst/workspace/scripts/.ipynb_checkpoints
analyst/workspace/.cache
analyst/workspace/craft_mlt_25k.pth
analyst/workspace/data

# vscode
isaac.code-workspace
isaac.code-workspace
3 changes: 2 additions & 1 deletion analyst/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

**The jupyter notebooks will be able to access data that is in the `$HOME/data` and `$HOME/data/bags`, therefore, make sure all the relevant bag files are there**

**If you want to run the OCR, make sure there is a `$HOME/data/str` folder with all the data**

For the Analyst notebook to be functional, it needs to start side-by-side with the database and the IUI (ISAAC user interface).
To do so, the recommended method is to use the remote docker images, as:

$ISAAC_SRC/scripts/docker/run.sh --analyst --no-sim --remote
$ISAAC_SRC/scripts/docker/run.sh --analyst --mount --no-sim --remote

The ISAAC UI is hosted in: http://localhost:8080
The ArangoDB database is hosted in: http://localhost:8529
Expand Down
443 changes: 443 additions & 0 deletions analyst/workspace/label_search.ipynb

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions anomaly/image_str/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**/image_str/result/
**/image_str/images/
*.json
craft_mlt_25k.pth
**/image_str/models/
**/image_str/test_images/
**/image_str/tests/
33 changes: 33 additions & 0 deletions anomaly/image_str/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2021, United States Government, as represented by the
# Administrator of the National Aeronautics and Space Administration.
#
# All rights reserved.
#
# The "ISAAC - Integrated System for Autonomous and Adaptive Caretaking
# platform" software is licensed under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(image_str)

## Compile as C++14, supported in ROS Kinetic and newer
add_compile_options(-std=c++14)


## Find catkin macros and libraries
find_package(catkin REQUIRED COMPONENTS
)

catkin_python_setup()

catkin_package(
)
18 changes: 18 additions & 0 deletions anomaly/image_str/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<package format="2">
<name>image_str</name>
<version>0.0.0</version>
<description>The OCR package</description>
<license>
Apache License, Version 2.0
</license>
<author email="astrobee-fsw@nx.arc.nasa.gov">
ISAAC Flight Software
</author>
<maintainer email="astrobee-fsw@nx.arc.nasa.gov">
ISAAC Flight Software
</maintainer>

<buildtool_depend>catkin</buildtool_depend>

</package>
52 changes: 52 additions & 0 deletions anomaly/image_str/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
\page str_anomaly Image STR

Image STR Anomaly Detection Documentation
====================

Overview
---------

The Image anomaly detector uses Scene Text Recognition (STR) to parse through sci-cam images of the ISS. It creates a database of all the
labels found on the ISS and displays the results of a search label using the panorama interface https://ivr.ndc.nasa.gov/isaac_panos/.


Prerequisites
---------

This package relies on the CRAFT-Pytorch and PARSeq libraries. To ensure the Image STR package works smoothly, clone the repos associated with the
libraries and build them as Python packages.

CRAFT-Pytorch

pip install git+https://github.com/marinagmoreira/CRAFT-pytorch.git

PARSeq

pip install git+https://github.com/marinagmoreira/parseq.git@focal#egg=parseq

The Image STR package also contains a setup file with all the other necessary Python packages.

pip install .

Running the Code
---------

The python code containing the label detection and search is in parse_img.py.

Parameters
```
--bag_path BAG_PATH Path to bag folder where the images came from.
--image_file IMAGE_FILE
Path to image to parse.
--image_folder IMAGE_FOLDER
Path to image folder to parse images.
--result_folder RESULT_FOLDER
Path to result folder to save results.
--increment INCREMENT
If True, will save the results of each individual
image.
--df_file DF_FILE If provided, will create an ocr using data from csv
file.
```

To see the demo, run the Analyst Notebook. Directions are specified in the readme.md in the Analyst Folder.
Empty file.
74 changes: 74 additions & 0 deletions anomaly/image_str/scripts/image_str/graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import glob
import os
import re

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from mpl_toolkits.mplot3d import Axes3D


def get_all_files(folder):
files = glob.glob(folder + "*_locations.csv")
return files


def graph(files):
fig = plt.figure()
ax = fig.add_subplot(projection="3d")

x = []
y = []
z = []
df = pd.DataFrame(
columns=["label", "PCL Intersection", "Mesh Intersection", "image", "location"]
)
for file in files:
# with open(file, "r") as f:
# for line in f:
# if "PCL Intersection" in line:
# nums = re.findall(
# r"[-+]?\d*\.\d+|\d+", line
# ) # [x, y, z, roll, pitch, yaw]
# x.append(float(nums[0]))
# y.append(float(nums[1]))
# z.append(float(nums[2]))
# data = np.genfromtxt(file, delimiter=';', dtype=str, missing_values=None)
# print("Line 900:", data[899])
df2 = pd.read_csv(file, delimiter=";", skiprows=[1])
df = pd.concat([df, df2])
# with open(file, 'r') as f:
# lines = f.readlines()'

# # Print line 900
# print("Line 900:", lines[899])
print(df)
for row in df["PCL Intersection"].tolist():
nums = re.findall(r"[-+]?\d*\.\d+|\d+", row)
x.append(float(nums[0]))
y.append(float(nums[1]))
z.append(float(nums[2]))
# nums = data[:, 1]
# nums = [re.findall(r"[-+]?\d*\.\d+|\d+", i) for i in nums]
# for i in nums:
# x.append(float(i[0]))
# y.append(float(i[1]))
# z.append(float(i[2]))

ax.scatter(x, y, z)

ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
plt.title("Label Locations on ISS")

plt.show()
# return plt


if __name__ == "__main__":
# files = get_all_files(os.getcwd())
# plt = graph(files)
# plt.show()
files = [os.path.join(os.getcwd(), "all_locations.csv")]
graph(files)
90 changes: 90 additions & 0 deletions anomaly/image_str/scripts/image_str/net_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import time
from collections import OrderedDict

import craft.craft_utils as craft_utils
import craft.file_utils as file_utils
import craft.imgproc as imgproc
import cv2
import image_str.utils as utils
import numpy as np
import torch
import torch.backends.cudnn as cudnn
import torch.nn as nn
from craft.craft import CRAFT
from torch.autograd import Variable


# Credit to CRAFT-pytorch
# https://github.com/clovaai/CRAFT-pytorch
def copyStateDict(state_dict):
if list(state_dict.keys())[0].startswith("module"):
start_idx = 1
else:
start_idx = 0
new_state_dict = OrderedDict()
for k, v in state_dict.items():
name = ".".join(k.split(".")[start_idx:])
new_state_dict[name] = v
return new_state_dict


def test_net(
net, image, text_threshold, link_threshold, low_text, cuda, poly, refine_net=None
):
""" """

t0 = time.time()

canvas_size = 1280
mag_ratio = 1.5

# resize
img_resized, target_ratio, size_heatmap = imgproc.resize_aspect_ratio(
image, canvas_size, interpolation=cv2.INTER_LINEAR, mag_ratio=mag_ratio
)
ratio_h = ratio_w = 1 / target_ratio

# preprocessing
x = imgproc.normalizeMeanVariance(img_resized)
x = torch.from_numpy(x).permute(2, 0, 1) # [h, w, c] to [c, h, w]
x = Variable(x.unsqueeze(0)) # [c, h, w] to [b, c, h, w]
if cuda:
x = x.cuda()

# forward pass
with torch.no_grad():
y, feature = net(x)

# make score and link map
score_text = y[0, :, :, 0].cpu().data.numpy()
score_link = y[0, :, :, 1].cpu().data.numpy()

# refine link
if refine_net is not None:
with torch.no_grad():
y_refiner = refine_net(y, feature)
score_link = y_refiner[0, :, :, 0].cpu().data.numpy()

t0 = time.time() - t0
t1 = time.time()

# Post-processing
boxes, polys = craft_utils.getDetBoxes(
score_text, score_link, text_threshold, link_threshold, low_text, poly
)

# coordinate adjustment
boxes = craft_utils.adjustResultCoordinates(boxes, ratio_w, ratio_h)
polys = craft_utils.adjustResultCoordinates(polys, ratio_w, ratio_h)
for k in range(len(polys)):
if polys[k] is None:
polys[k] = boxes[k]

t1 = time.time() - t1

# render results (optional)
render_img = score_text.copy()
render_img = np.hstack((render_img, score_link))
ret_score_text = imgproc.cvt2HeatmapImg(render_img)

return boxes, polys, ret_score_text
Loading
Loading