-
-
Notifications
You must be signed in to change notification settings - Fork 16.6k
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
Fix detect.py --view-img
for non-ASCII paths
#7093
Conversation
for more information, see https://pre-commit.ci
@Zengyf-CVer thanks for the PR! I think we should use the strategy I raised in #7139 (comment) for this |
@Zengyf-CVer looks like unicode escape is faster than is_chinese, so makes sense just to always apply it rather than to check first: p = 'acbadsfasdfasdfadslfkhadsfhjlasdfhljj.jpg'
%timeit p.encode('unicode_escape')
462 ns ± 3.47 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
%timeit is_chinese(p)
1.15 µs ± 11.3 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each) |
@Zengyf-CVer ok I've updated per my recommendation and replaced - cv2.imshow(p.encode('unicode_escape').decode(), im)
+ cv2.imshow(p.encode().decode('utf-8', 'ignore'), im) Does this work for your use case? If not can you send me the image or string that is causing the problem? |
@glenn-jocher # video path:
/home/zyf/文档/yolov5/video/202202241928.mp4
# run:
python detect.py --weights ./yolov5s.pt --source ./video/ --view-img |
@Zengyf-CVer here are my path.encode('unicode_escape').decode() path.encode('').decode('utf-8', 'ignore') |
@glenn-jocher |
@glenn-jocher imshow_(path.encode('unicode_escape').decode(), im) But this doesn't show up: imshow_(path.encode().decode('utf-8', 'ignore'), im) |
detect.py --view-img
for non-ASCII paths
@Zengyf-CVer got it. I've reverted to |
@Zengyf-CVer PR is merged. Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐ |
* Update detect.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update general.py * Update detect.py * Update general.py * Update general.py * Update general.py * Update general.py * Update general.py * Update general.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update general.py * Update general.py Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Glenn Jocher <[email protected]>
@glenn-jocher
I found a solution to the problem mentioned in #7075, the reason is that my yolov5 project path includes Chinese, so
cv2.imshow(str(p), im0)
This line of code cannot display the window, resulting in the inability to display pictures and videos, I will fix this bug.🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
🌟 Summary
Improved OpenCV functions for better Chinese character handling in file paths.
📊 Key Changes
cv2.imshow
to prevent recursion errors.imshow
function.cv2.imread
,cv2.imwrite
, andcv2.imshow
to utilize the new, improved functions supporting Chinese character file paths.🎯 Purpose & Impact