æšè«çµæãã¿ãŒããã«ã§èŠã
ç»åã¯libsixelãŠã§ããµã€ããã
ã¢ãããŒã·ã§ã³
ãªã¢ãŒããã·ã³ã«æ¥ç¶ããå Žåãéåžžãç»åçµæãèŠèŠåããããšã¯äžå¯èœã§ããããGUIãæã€ããŒã«ã«ããã€ã¹ã«ããŒã¿ã移åããå¿
èŠããããŸããVSCodeçµ±åã¿ãŒããã«ã¯ãç»åãçŽæ¥ã¬ã³ããªã³ã°ããããšãã§ããŸããããã¯ãVSCodeçµ±åã¿ãŒããã«ã䜿çšããç°¡åãªãã¢ã³ã¹ãã¬ãŒã·ã§ã³ã§ãã ultralytics
ãš äºæž¬çµæ.
èŠå
LinuxãšMacOSã®ã¿å¯Ÿå¿ãããã§ãã¯ããŠãã ããã VSCodeãªããžããªãã§ã㯠åé¡ã¹ããŒã¿ã¹ããã㯠ããã¥ã¡ã³ããŒã·ã§ã³ ã䜿çšããŠã¿ãŒããã«ã§ç»åã衚瀺ããããã®WindowsãµããŒãã«é¢ããææ°æ
å ±ã«ã€ããŠã¯ããã¡ããã芧ãã ããã sixel
.
çµ±å端æ«ã䜿çšããŠç»åã衚瀺ããããã®VSCodeäºæãããã³ã«ã¯æ¬¡ã®ãšããã§ãã sixel
ãã㊠iTerm
.ãã®ã¬ã€ãã§ã¯ sixel
ãããã³ã«ã䜿çšããã
ããã»ã¹
-
ãŸããèšå®ãæå¹ã«ããŸãã
terminal.integrated.enableImages
ãããŠterminal.integrated.gpuAcceleration
ãVSCodeã«è¿œå ããã"terminal.integrated.gpuAcceleration": "auto" # "auto" is default, can also use "on" "terminal.integrated.enableImages": false
-
ãã€ã³ã¹ããŒã«ããŸãã
python-sixel
ã©ã€ãã©ãªãŒãä»®æ³ç°å¢ã«ã€ã³ã¹ããŒã«ããŸãããã㯠ãã©ãŒã¯ ã®PySixel
çŸåšã¯ã¡ã³ããã³ã¹ãããŠããªãã -
ã¢ãã«ãããŒãããŠæšè«ãå®è¡ããçµæãããããããŠå€æ°ã«æ ŒçŽããŸããæšè«ã®åŒæ°ãšçµæã®æäœã«ã€ããŠã¯ãpredict modeã®ããŒãžãåç §ããŠãã ããã
from ultralytics import YOLO # Load a model model = YOLO("yolo11n.pt") # Run inference on an image results = model.predict(source="ultralytics/assets/bus.jpg") # Plot inference results plot = results[0].plot() # (1)!
- 䜿çšå¯èœãªåŒæ°ã«ã€ããŠã¯ãplotã¡ãœããã®ãã©ã¡ãŒã¿ãåç §ããŠãã ããã
-
ã§ã¯ã次ã®ããã«äœ¿ãã ãªãŒãã³CV ãå€æããã
numpy.ndarray
ãžã®bytes
ããŒã¿ã䜿çšããŸãããããŠio.BytesIO
ã§ããã¡ã€ã«ã®ãããªããªããžã§ã¯ããäœããimport io import cv2 # Results image as bytes im_bytes = cv2.imencode( ".png", # (1)! plot, )[1].tobytes() # (2)! # Image bytes as a file-like object mem_file = io.BytesIO(im_bytes)
- ä»ã®ç»åæ¡åŒµåã䜿ãããšãå¯èœã ã
- ã€ã³ããã¯ã¹
1
ãå¿ èŠã§ããã
-
ãäœæããã
SixelWriter
ã€ã³ã¹ã¿ã³ã¹ãäœæã.draw()
ã¡ãœããã䜿ã£ãŠç«¯æ«ã«ç»åãæç»ããã
æšè«çµæã®äŸ
å±éº
ãã®äŸãåç»ãã¢ãã¡ãŒã·ã§ã³GIFãã¬ãŒã ã§äœ¿çšããããšã¯ãã¹ããããŠããŸãããèªå·±è²¬ä»»ã§ãè©Šããã ããã
ã³ãŒãäŸ
import io
import cv2
from sixel import SixelWriter
from ultralytics import YOLO
# Load a model
model = YOLO("yolo11n.pt")
# Run inference on an image
results = model.predict(source="ultralytics/assets/bus.jpg")
# Plot inference results
plot = results[0].plot() # (3)!
# Results image as bytes
im_bytes = cv2.imencode(
".png", # (1)!
plot,
)[1].tobytes() # (2)!
mem_file = io.BytesIO(im_bytes)
w = SixelWriter()
w.draw(mem_file)
- ä»ã®ç»åæ¡åŒµåã䜿ãããšãå¯èœã ã
- ã€ã³ããã¯ã¹
1
ãå¿ èŠã§ããã - 䜿çšå¯èœãªåŒæ°ã«ã€ããŠã¯ãplotã¡ãœããã®ãã©ã¡ãŒã¿ãåç §ããŠãã ããã
ããã
ã䜿çšããå¿
èŠããããããããªãã clear
ãã¯ãªãã¯ãããšã端æ«å
ã®ç»åã®è¡šç€ºããæ¶ããããšãã§ããã
ããããã質å
macOSãLinuxã®VSCodeã¿ãŒããã«ã§ãYOLO ã®æšè«çµæãèŠãã«ã¯ïŒ
macOSãŸãã¯Linuxäžã®VSCodeã¿ãŒããã«ã§YOLO æšè«çµæã衚瀺ããã«ã¯ã以äžã®æé ã«åŸã£ãŠãã ããïŒ
-
å¿ èŠãªVSCodeèšå®ãæå¹ã«ããïŒ
-
sixelã©ã€ãã©ãªãã€ã³ã¹ããŒã«ããïŒ
-
YOLO ã¢ãã«ãããŒãããæšè«ãå®è¡ããïŒ
-
æšè«çµæã®ç»åããã€ãã«å€æããã¿ãŒããã«ã«è¡šç€ºããïŒ
詳ããã¯äºæž¬ã¢ãŒãã®ããŒãžãã芧ãã ããã
ãªãsixelãããã³ã«ã¯LinuxãšmacOSã§ããåäœããªãã®ã§ããïŒ
sixelãããã³ã«ã¯çŸåšãLinuxãšmacOSã§ã®ã¿ãµããŒããããŠããããããã®ãã©ãããã©ãŒã ã¯ãsixelã°ã©ãã£ãã¯ã¹ãšäºææ§ã®ãããã€ãã£ã端æ«æ©èœãåããŠããããã§ãããsixelã䜿çšããã¿ãŒããã«ã°ã©ãã£ãã¯ã¹ã®WindowsãµããŒãã¯ãŸã éçºäžã§ããWindowsã®äºææ§ã«é¢ããææ°æ å ±ã«ã€ããŠã¯ãVSCode Issue Statusãš ããã¥ã¡ã³ãã確èªããŠãã ããã
VSCodeã¿ãŒããã«ã§ç»åã衚瀺ããéã«åé¡ãçºçããå Žåã¯ïŒ
sixelã䜿çšããŠVSCode端æ«ã§ç»åã衚瀺ããéã«åé¡ãçºçããå ŽåïŒ
-
VSCodeã®å¿ èŠãªèšå®ãæå¹ã«ãªã£ãŠããããšã確èªããïŒ
-
sixelã©ã€ãã©ãªã®ã€ã³ã¹ããŒã«ã確èªããïŒ
-
ç»åããŒã¿ã®å€æãšããããã³ãŒãã«ãšã©ãŒããªãã確èªããŠãã ãããäŸãã°
ããã§ãåé¡ã解決ããªãå Žåã¯ãVSCodeãªããžããªãåç §ããããããã¡ãœãããã©ã¡ãŒã¿ã»ã¯ã·ã§ã³ãåç §ããŠãã ããã
YOLO sixelã䜿ã£ãŠãããªæšè«ã®çµæã端æ«ã«è¡šç€ºããããšã¯ã§ããŸããïŒ
端æ«ã§sixelã䜿çšããŠãããªæšè«çµæãã¢ãã¡ãŒã·ã§ã³GIFãã¬ãŒã ã衚瀺ããããšã¯ãçŸåšã®ãšãããã¹ããããŠãããããµããŒããããŠããªãå¯èœæ§ããããŸããéæ¢ç»åããå§ããäºææ§ã確èªããããšããå§ãããŸããããã©ãŒãã³ã¹ã®å¶çŽã念é ã«çœ®ããèªå·±è²¬ä»»ã§ãããªçµæãè©ŠããŠãã ãããæšè«çµæã®ããããã«é¢ãã詳现ã¯ãäºæž¬ã¢ãŒãã®ããŒãžãã芧ãã ããã
ã®ãã©ãã«ã·ã¥ãŒãã£ã³ã°ã¯ã©ãããã°ããã§ããïŒ python-sixel
å³æžé€šïŒ
ã®åé¡ããã©ãã«ã·ã¥ãŒãã£ã³ã°ããã«ã¯ python-sixel
å³æžé€š
-
ã©ã€ãã©ãªãä»®æ³ç°å¢ã«æ£ããã€ã³ã¹ããŒã«ãããŠããããšã確èªããŠãã ããïŒ
-
å¿ èŠãªPython ãã·ã¹ãã ã®äŸåé¢ä¿ãããããšã確èªããã
-
ãã®ä»ã®ããã¥ã¡ã³ããã³ãã¥ããã£ã»ãµããŒãã«ã€ããŠã¯ãpython-sixelGitHub ãªããžããªãåç §ã®ããšã
-
ã³ãŒãã«æœåšçãªãšã©ãŒããªããåãã§ãã¯ããŠãã ããã
SixelWriter
ãšç»åããŒã¿å€æã®ã¹ãããã
YOLO ã¢ãã«ãšsixelã®çµ±åã«é¢ããæŽãªãæ¯æŽã«ã€ããŠã¯ããšã¯ã¹ããŒããš äºæž¬ã¢ãŒãã®ããã¥ã¡ã³ãããŒãžãåç §ããŠãã ããã