-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to GitHub API limits, only the first 60 comments can be shown.
self.windows = dict() | ||
self.windows = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function opencv_windows_management.__init__
refactored with the following changes:
- Replace
dict()
with{}
(dict-literal
)
@@ -12,6 +12,7 @@ | |||
|
|||
""" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 39-46
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Swap positions of nested conditionals (
swap-nested-ifs
) - Hoist nested repeated code outside conditional statements (
hoist-similar-statement-from-if
)
This removes the following comments ( why? ):
#TODO 分辨率太大,需要缩放
# if t.any():
# if temp == img:
# t = temp == img
# if t.all():
cv2.imshow('frame_no'+str(frame_no), frame) | ||
cv2.imshow(f'frame_no{frame_no}', frame) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 27-27
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Remove unnecessary calls to
str()
from formatted values in f-strings (remove-str-from-fstring
)
if ret is True: | ||
|
||
frame = cv2.resize(frame, (640, 480)) | ||
if ret is not True: | ||
break | ||
|
||
# write the flipped frame | ||
out.write(frame) | ||
frame = cv2.resize(frame, (640, 480)) | ||
|
||
cv2.imshow('frame', frame) | ||
# write the flipped frame | ||
out.write(frame) | ||
|
||
else: | ||
break | ||
cv2.imshow('frame', frame) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 21-31
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
cv2.imwrite(id_generator() + '.jpg', frame) | ||
cv2.imwrite(f'{id_generator()}.jpg', frame) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 32-32
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
y = np.flipud(h) | ||
return y | ||
return np.flipud(h) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function hist_curve
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
plt.suptitle('method: ' + meth) | ||
plt.suptitle(f'method: {meth}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 56-56
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
cv2.imwrite(id_generator() + '.jpg', frame2) | ||
cv2.imwrite(f'{id_generator()}.jpg', frame2) | ||
|
||
# Capture frame-by-frame | ||
ret, frame = cap.read() | ||
m = mse(cv2.cvtColor(temp, cv2.COLOR_BGR2GRAY), cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)) | ||
print('mse', m, '----\n') | ||
if abs(m - tm) < 2: # 静止画面,不用重复计算 | ||
if abs(m - tm) < 2: | ||
continue | ||
else: | ||
temp = frame.copy() | ||
tm = m | ||
temp = frame.copy() | ||
tm = m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 53-63
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
This removes the following comments ( why? ):
# 静止画面,不用重复计算
txt = 'black' | ||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | ||
ret, threshold = cv2.threshold(gray, 100, 255, cv2.THRESH_BINARY) | ||
|
||
c = Counter(list(threshold.flatten())) | ||
print(c.most_common()) | ||
if c.most_common()[0][0] != 0: | ||
txt = 'white' | ||
txt = 'white' if c.most_common()[0][0] != 0 else 'black' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function detect_weiqi
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Move setting of default value for variable into
else
branch (introduce-default-else
) - Replace if statement with if expression (
assign-if-exp
)
# Apply ratio test | ||
# 比值测试,首先获取与 A距离最近的点 B (最近)和 C (次近), | ||
# 只有当 B/C 小于阀值时(0.75)才被认为是匹配, | ||
# 因为假设匹配是一一对应的,真正的匹配的理想距离为0 | ||
good = [] | ||
for m, n in matches: | ||
if m.distance < 0.75 * n.distance: | ||
good.append([m]) | ||
|
||
good = [[m] for m, n in matches if m.distance < 0.75 * n.distance] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 28-36
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
This removes the following comments ( why? ):
# Apply ratio test
# 比值测试,首先获取与 A距离最近的点 B (最近)和 C (次近),
# 因为假设匹配是一一对应的,真正的匹配的理想距离为0
# 只有当 B/C 小于阀值时(0.75)才被认为是匹配,
@@ -15,6 +15,7 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 41-41
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
@@ -8,6 +8,7 @@ | |||
findHomography.py:联合使用特征提取和 calib3d 模块中的 findHomography 在复杂图像中查找已知对象 | |||
""" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 31-35
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
This removes the following comments ( why? ):
# store all the good matches as per Lowe's ratio test.
cv2.imwrite(fname[:6] + '.png', img) | ||
cv2.imwrite(f'{fname[:6]}.png', img) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 75-75
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
for i, (m, n) in enumerate(matches): | ||
for m, n in matches: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 67-67
refactored with the following changes:
- Remove unnecessary calls to
enumerate
when the index is not used (remove-unused-enumerate
)
hist = np.hstack(hists) # hist is a 64 bit vector | ||
return hist | ||
return np.hstack(hists) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function hog
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# hist is a 64 bit vector
print("[INFO] processing image {}/{}".format(i + 1, len(captcha_image_files))) | ||
print(f"[INFO] processing image {i + 1}/{len(captcha_image_files)}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 18-88
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
) - Merge consecutive list appends into a single extend (
merge-list-appends-into-extend
)
letter_image_regions.append((x, y, half_width, h)) | ||
letter_image_regions.append((x + half_width, y, half_width, h)) | ||
letter_image_regions.extend( | ||
((x, y, half_width, h), (x + half_width, y, half_width, h)) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 60-108
refactored with the following changes:
- Merge consecutive list appends into a single extend (
merge-list-appends-into-extend
) - Replace call to format with f-string (
use-fstring-for-formatting
)
# taking only 10% of histogram diff, since it's less accurate than template method | ||
commutative_image_diff = (img_hist_diff / 10) + img_template_diff | ||
return commutative_image_diff | ||
return (img_hist_diff / 10) + img_template_diff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_image_difference
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# taking only 10% of histogram diff, since it's less accurate than template method
text = "{} ({})".format(barcodeData, barcodeType) | ||
text = f"{barcodeData} ({barcodeType})" | ||
cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, | ||
0.5, (0, 0, 255), 2) | ||
|
||
# print the barcode type and data to the terminal | ||
print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData)) | ||
print(f"[INFO] Found {barcodeType} barcode: {barcodeData}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function main
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
@@ -4,6 +4,7 @@ | |||
Utility for measuring python opencv API coverage by samples. | |||
''' | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 15-15
refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
) - Replace unneeded comprehension with generator (
comprehension-to-generator
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if pool is None: | ||
ires = it.imap(f, params) | ||
else: | ||
ires = pool.imap(f, params) | ||
|
||
ires = it.imap(f, params) if pool is None else pool.imap(f, params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function affine_detect
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
@@ -13,6 +13,7 @@ | |||
<image mask> defaults to ../data/left*.jpg | |||
''' | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 37-109
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
This removes the following comments ( why? ):
# default
M = np.float64([[ cx, 0, tx], | ||
[ 0, cy, ty], | ||
[ 0, 0, 1]]) | ||
return M | ||
return np.float64([[cx, 0, tx], [0, cy, ty], [0, 0, 1]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function rect2rect_mtx
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if PY3: | ||
output = it.zip_longest(fillvalue=fillvalue, *args) | ||
else: | ||
output = it.izip_longest(fillvalue=fillvalue, *args) | ||
return output | ||
return ( | ||
it.zip_longest(fillvalue=fillvalue, *args) | ||
if PY3 | ||
else it.izip_longest(fillvalue=fillvalue, *args) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function grouper
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if PY3: | ||
img0 = next(imgs) | ||
else: | ||
img0 = imgs.next() | ||
img0 = next(imgs) if PY3 else imgs.next() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function mosaic
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if PY3: | ||
cur_func_name = next(dist_func_names) | ||
else: | ||
cur_func_name = dist_func_names.next() | ||
cur_func_name = next(dist_func_names) if PY3 else dist_func_names.next() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 52-55
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if PY3: | ||
cur_func_name = next(dist_func_names) | ||
else: | ||
cur_func_name = dist_func_names.next() | ||
cur_func_name = next(dist_func_names) if PY3 else dist_func_names.next() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 93-96
refactored with the following changes:
- Swap positions of nested conditionals (
swap-nested-ifs
) - Hoist nested repeated code outside conditional statements (
hoist-similar-statement-from-if
) - Replace if statement with if expression (
assign-if-exp
)
for i in xrange(cluster_n): | ||
for _ in xrange(cluster_n): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function make_gaussians
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
y=np.flipud(h) | ||
return y | ||
return np.flipud(h) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function hist_curve
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
@@ -8,6 +8,7 @@ | |||
image argument defaults to ../data/pic1.png | |||
''' | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 31-51
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
This removes the following comments ( why? ):
# HoughLines
# HoughLinesP
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!