Skip to content

Commit c549c7a

Browse files
KDharmarajanDevshreystechtipsayush0624Matthew-Haddad
authored
Background rm (#51)
* initial slot machine algo and watershed bg removal * add haze and background removal initia files * initial slot machine algo and watershed bg removal * add haze and background removal initia files * Added depth_map as a TaskPerceiver * adapt Background Removal for the visualizer * Added DepthMap With Histogram For Vis * PCA experimentation with Depth * add temporal blur function to remove background artifacts * Cleaned Up Various Algorithms * Deleted algo_stats * Cleaned Up Imports This commit cleans up different imports and also deletes any out of place relics. * switch to knn based background algo * Added MBD * Added MBD to Code * Cythonized the saliency_mbd * Removed Internal Resizing * add bitwise and for saliency and knn * Fixed prev returned frame * Updated combined file * Removed experiment * added build firle * use numpy oriented C functions for better cython performance Next steps include adding support for skimage, cython views (maybe) * Added iou function * Cleaned Up Combined Algorithm This commit cleans up all unused code and imports. * add gitignore and readme for cython * Added Contours * Added Contours and Centroid Plotting * Implemented basics of switching * Fixed to being in opencv version 4 * Added slider to change if both algorithms should run * Added 0 area protections * Added sliders for area_percentage_weight and centroid_distance_weight * Added multi-contour output * Updated to reflect debug mode * Integrated saliency detection with roulette algo * saliency with the predefined array and loops * Added dice detector * finalize cleaner version of saliency with "chunks" * Adding DiceLabels.csv (#50) This file contains dice labels for the dice.mp4 video for use as training data. Co-authored-by: Matthew-Haddad <[email protected]> Co-authored-by: Shrey A <[email protected]> Co-authored-by: ayush0624 <[email protected]> Co-authored-by: Matthew-Haddad <[email protected]>
1 parent 3c7ecca commit c549c7a

25 files changed

+17238
-6
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# Byte-compiled / optimized / DLL files
66
__pycache__/
7+
build/
78
.ipynb_checkpoints/
89
*.py[cod]
910
*$py.class
@@ -14,9 +15,11 @@ __pycache__/
1415

1516
# C extensions
1617
*.so
18+
*.o
1719

1820
# IDE files
1921
.idea
2022
.vs_code/
23+
.vscode/
2124

2225
data/

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ and install it
2727

2828
Also, our training data is stored here https://www.dropbox.com/sh/rrbfqfutrmifrxs/AAAfXxlcCtWZmUELp4wXyTIxa?dl=0 so download it and unzip it in the same folder as `perception`.
2929

30+
### Cython
31+
To compile cythonized code, run the following commands after `cd`ing into the folder with Cython `setup.py`
32+
33+
python setup.py build_ext --inplace
34+
cythonize file_to_cythonize.pyx
35+
3036

3137
## misc:
3238
Misc code, camera calibration etc.

algo_stats

23.6 KB
Binary file not shown.

misc/general_bg_rm.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import cv2 as cv
2+
import numpy as np
3+
import os
4+
import argparse
5+
parser = argparse.ArgumentParser()
6+
parser.add_argument("file", help="file")
7+
args = parser.parse_args()
8+
from dark_channel.handler import process_frame as dark_channel
9+
10+
11+
12+
def DarkChannel(im):
13+
b,g,r = cv.split(im)
14+
dc = cv.min(cv.min(r,g),b);
15+
kernel = cv.getStructuringElement(cv.MORPH_RECT,(im.shape[0],im.shape[1]))
16+
dark = cv.erode(dc,kernel)
17+
return dark
18+
19+
def resize_frame(frame,ratio = 0.4):
20+
return cv.resize(frame,(int(frame.shape[1]*ratio),int(frame.shape[0]*ratio)))
21+
22+
def save_frames(frames,folder):
23+
os.mkdir(folder)
24+
[cv.imwrite(f'{folder}/{frame}.png', frames[frame]) for frame in frames]
25+
26+
def show_frames(frames):
27+
[cv.imshow(frame,frames[frame]) for frame in frames]
28+
29+
def analyze(src):
30+
31+
# src = cv.imread(fn);
32+
# src = resize_frame(src)
33+
img = src
34+
gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
35+
ret, thresh = cv.threshold(gray,0,255,cv.THRESH_BINARY_INV+cv.THRESH_OTSU)
36+
37+
# noise removal
38+
kernel = np.ones((3,3),np.uint8)
39+
opening = cv.morphologyEx(thresh,cv.MORPH_OPEN,kernel, iterations = 2)
40+
# # sure background area
41+
# sure_bg = cv.dilate(opening,kernel,iterations=3)
42+
# # Finding sure foreground area
43+
# dist_transform = cv.distanceTransform(opening,cv.DIST_L2,5)
44+
# ret, sure_fg = cv.threshold(dist_transform,0.7*dist_transform.max(),255,0)
45+
# # Finding unknown region
46+
# sure_fg = np.uint8(sure_fg)
47+
# unknown = cv.subtract(sure_bg,sure_fg)
48+
49+
# # Marker labelling
50+
# ret, markers = cv.connectedComponents(sure_fg)
51+
# # Add one to all labels so that sure background is not 0, but 1
52+
# markers = markers+1
53+
# # Now, mark the region of unknown with zero
54+
# markers[unknown==255] = 0
55+
# markers = cv.watershed(img,markers)
56+
# orig = resize_frame(cv.imread(fn))
57+
# orig[markers == -1] = [255,0,0]
58+
return thresh
59+
# frames = {'test':thresh,'dist':dist_transform,'sure_fg':sure_fg,'sure_bg':sure_bg,'unknown':unknown,'marked':orig}
60+
# show_frames(frames)
61+
# save_frames(frames,'binary_inv_dc/orig')
62+
# cv.waitKey()
63+
64+
65+
if __name__ == '__main__':
66+
print(args.file)
67+
cap = cv.VideoCapture(args.file)
68+
while not cap.isOpened():
69+
cap = cv.VideoCapture(args.file)
70+
cv.waitKey(1000)
71+
print ("Wait for the header")
72+
while(True):
73+
ret, frame = cap.read()
74+
if ret:
75+
frame = resize_frame(frame, 0.25)
76+
dark = dark_channel(frame)[0]
77+
# cv.imshow('OTSU+Dark',analyze(dark))
78+
show_frames({'OTSU':analyze(frame),'dark':dark,'OTSU+DARK':analyze(dark),'orig':frame})
79+
if cv.waitKey(1) & 0xFF == ord('q'):
80+
break
81+
if cv.waitKey(32) == ord(' '):
82+
while(not cv.waitKey(32) == ord(' ')):
83+
continue
84+
cv.waitKey(-1)

perception/__init__.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@
33
import perception.tasks.gate.GateSegmentationAlgoA as GateSegA
44
import perception.tasks.gate.GateSegmentationAlgoB as GateSegB
55
import perception.tasks.gate.GateSegmentationAlgoC as GateSegC
6-
# import perception.tasks as tasks
6+
import perception.tasks.segmentation.saliency_detection.MBD as MBD
7+
from perception.tasks.segmentation.COMB_SAL_BG import COMB_SAL_BG
8+
import perception.vis.TestTasks.BackgroundRemoval as BackgroundRemoval
9+
import perception.tasks.roulette.color_detection as RouletteColorDetector
10+
from perception.tasks.dice.DiceDetector import DiceDetector
711

812
ALGOS = {
913
'test': TestAlgo.TestAlgo,
1014
'gateseg': GateSeg.GateCenterAlgo,
1115
'gatesegA': GateSegA.GateSegmentationAlgoA,
1216
'gatesegB': GateSegB.GateSegmentationAlgoB,
13-
'gatesegC': GateSegC.GateSegmentationAlgoC
17+
'gatesegC': GateSegC.GateSegmentationAlgoC,
18+
'MBD': MBD.MBD,
19+
'bg-rm': BackgroundRemoval.BackgroundRemoval,
20+
'combined': COMB_SAL_BG,
21+
'roulette': RouletteColorDetector.RouletteColorDetector,
22+
'dice': DiceDetector
1423
}

0 commit comments

Comments
 (0)