Skip to content

Commit ec6787f

Browse files
authored
Merge pull request #25 from fernaper/development
🐛 Fixed bugs with distribution package
2 parents 26dae96 + 58204a4 commit ec6787f

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

opencv_draw_tools/SelectZone.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import cv2
66

7-
import tags_constraint
7+
from opencv_draw_tools.tags_constraint import *
88

99
"""
1010
You can change it.
@@ -406,8 +406,8 @@ def select_multiple_zones(frame, all_selected_zones, all_tags=None, alpha=0.9, c
406406
all_tags_shapes = []
407407
for i, zone in enumerate(all_selected_zones):
408408
all_tags_shapes.append(get_shape_tags(zone, all_tags[i], margin=margin))
409-
# Here you could pass the frame if you want to see where tags_constraint thinks the tags will be. Just: frame=frame \/
410-
best_position = tags_constraint.get_possible_positions(f_width, f_height, all_selected_zones, all_tags_shapes, margin=margin, frame=[])
409+
# Here you could pass the frame if you want to see where get_possible_positions thinks the tags will be. Just: frame=frame \/
410+
best_position = get_possible_positions(f_width, f_height, all_selected_zones, all_tags_shapes, margin=margin, frame=[])
411411
for i, zone in enumerate(all_selected_zones):
412412
if best_position:
413413
position = best_position[i]
@@ -430,9 +430,9 @@ def webcam_test():
430430
if ret:
431431
keystroke = cv2.waitKey(1)
432432
position1 = (0.33,0.2,0.66,0.8)
433-
tags1 = ['MIT License', '(C) Copyright\n Fernando\n Perez\n Gutierrez\n hola\n', 'mundo']
434-
position2 = (0.22,0.4,0.3,0.88)
435-
tags2 = ['Release', 'v1.0.0']
433+
tags1 = ['MIT License', '(C) Copyright\n Fernando\n Perez\n Gutierrez', '@fernaperg']
434+
position2 = (0.1,0.4,0.3,0.88)
435+
tags2 = ['Release', 'v1.0.1']
436436
frame = select_multiple_zones(frame, [position1,position2], all_tags=[tags1,tags2], color=(14,28,200),
437437
thickness=2, filled=True, normalized=True)
438438
cv2.imshow(window_name, frame)

opencv_draw_tools/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from opencv_draw_tools.SelectZone import *
2+
import opencv_draw_tools.tags_constraint
23

34
name = 'opencv_draw_tools'
45
help = '''
56
MIT License
67
Copyright (c) 2019 Fernando Perez
78
For more information visit: https://github.com/fernaper/opencv-draw-tools
89
Also you can write complete_help to view full information'''
9-
__version__ = '1.0.0'
10+
__version__ = '1.0.1'
1011

1112
complete_help = '''
1213
{} - v{}

opencv_draw_tools/tags_constraint.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ def rectangle_collision_list_rectangles (rectangle, list_rectangles):
1717
return True
1818
return False
1919

20+
def is_valid(position, frame_shape, other_selected_zones):
21+
x1, y1, x2, y2 = position
22+
width, height = frame_shape
23+
return x1 >= 0 and x2 > x1 and y1 >= 0 and y2 > y1 and x2 <= width and y2 <= height and \
24+
not rectangle_collision_list_rectangles(position, other_selected_zones)
25+
2026
def get_possible_positions(width, height, all_selected_zones, all_tags_shapes, margin=5, frame=[]):
2127
problem = Problem()
2228
for i, rectangle in enumerate(all_selected_zones):
@@ -29,8 +35,7 @@ def get_possible_positions(width, height, all_selected_zones, all_tags_shapes, m
2935
other_selected_zones = all_selected_zones[:i] + all_selected_zones[i+1:]
3036
for side in sides:
3137
# Only accepts zones inside the frame with tags not inside other selections
32-
if rectangle_collision_rectangle(side[:-1], (0, 0, width, height)) and \
33-
not rectangle_collision_list_rectangles(side[:-1], other_selected_zones):
38+
if is_valid(side[:-1], (width,height), other_selected_zones):
3439
valid_sides.append(side)
3540
problem.addVariable('zone_{}'.format(i), valid_sides)
3641

@@ -66,6 +71,7 @@ def get_possible_positions(width, height, all_selected_zones, all_tags_shapes, m
6671
info_zone = best_solution['zone_{}'.format(i)]
6772
# This is for testing where this method thinks tags will be poisitionated
6873
if len(frame):
74+
#print(info_zone)
6975
cv2.rectangle(frame, (info_zone[0],info_zone[1]),(info_zone[2], info_zone[3]), (0,255,0),0)
7076
if info_zone[0] >= 0 and info_zone[2] <= width and info_zone[1] >= 0 and info_zone[3] <= height:
7177
final_ans.append(info_zone[4])

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name='opencv-draw-tools-fernaperg',
8-
version='1.0.0',
8+
version='1.0.1',
99
author='Fernando Pérez',
1010
author_email='[email protected]',
1111
description='Library to help the drawing process with OpenCV. Thought to add labels to the images. Classification of images, etc.',

0 commit comments

Comments
 (0)