์ฝ˜ํ…์ธ ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

ํ„ฐ๋ฏธ๋„์—์„œ ์ถ”๋ก  ๊ฒฐ๊ณผ ๋ณด๊ธฐ

ํ„ฐ๋ฏธ๋„์˜ ์‹์…€ ์ด๋ฏธ์ง€ ์˜ˆ์‹œ

libsixel ์›น์‚ฌ์ดํŠธ์˜ ์ด๋ฏธ์ง€์ž…๋‹ˆ๋‹ค.

๋™๊ธฐ ๋ถ€์—ฌ

์›๊ฒฉ ๋จธ์‹ ์— ์—ฐ๊ฒฐํ•˜๋ฉด ์ผ๋ฐ˜์ ์œผ๋กœ ์ด๋ฏธ์ง€ ๊ฒฐ๊ณผ๋ฅผ ์‹œ๊ฐํ™”ํ•  ์ˆ˜ ์—†๊ฑฐ๋‚˜ GUI๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋กœ์ปฌ ์žฅ์น˜๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ด๋™ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. VSCode ํ†ตํ•ฉ ํ„ฐ๋ฏธ๋„์„ ์‚ฌ์šฉํ•˜๋ฉด ์ด๋ฏธ์ง€๋ฅผ ์ง์ ‘ ๋ Œ๋”๋งํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ์ด๋ฅผ ๋‹ค์Œ๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์งง์€ ๋ฐ๋ชจ์ž…๋‹ˆ๋‹ค. ultralytics ์™€ ํ•จ๊ป˜ ์˜ˆ์ธก ๊ฒฐ๊ณผ.

๊ฒฝ๊ณ 

Linux ๋ฐ MacOS์™€๋งŒ ํ˜ธํ™˜๋ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์—์„œ VSCode ๋ฆฌํฌ์ง€ํ† ๋ฆฌํ™•์ธ ์ด์Šˆ ์ƒํƒœ๋˜๋Š” ๋ฌธ์„œ ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ„ฐ๋ฏธ๋„์—์„œ ์ด๋ฏธ์ง€๋ฅผ ๋ณด๊ธฐ ์œ„ํ•œ Windows ์ง€์›์— ๋Œ€ํ•œ ์—…๋ฐ์ดํŠธ๋ฅผ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค. sixel.

ํ†ตํ•ฉ ํ„ฐ๋ฏธ๋„์„ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€๋ฅผ ๋ณด๊ธฐ ์œ„ํ•œ VSCode ํ˜ธํ™˜ ํ”„๋กœํ† ์ฝœ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. sixel ๊ทธ๋ฆฌ๊ณ  iTerm. ์ด ๊ฐ€์ด๋“œ์—์„œ๋Š” sixel ํ”„๋กœํ† ์ฝœ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

ํ”„๋กœ์„ธ์Šค

  1. ๋จผ์ € ์„ค์ •์„ ํ™œ์„ฑํ™”ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. terminal.integrated.enableImages ๊ทธ๋ฆฌ๊ณ  terminal.integrated.gpuAcceleration ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

    "terminal.integrated.gpuAcceleration": "auto" # "auto" is default, can also use "on"
    "terminal.integrated.enableImages": false
    

    VSCode ํ™œ์„ฑํ™” ํ„ฐ๋ฏธ๋„ ์ด๋ฏธ์ง€ ์„ค์ •

  2. ์„ค์น˜ python-sixel ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”. ์ด๊ฒƒ์€ ํฌํฌ ์˜ PySixel ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋” ์ด์ƒ ์œ ์ง€ ๊ด€๋ฆฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

    pip install sixel
    
  3. ๋ชจ๋ธ์„ ๋กœ๋“œํ•˜๊ณ  ์ถ”๋ก ์„ ์‹คํ–‰ํ•œ ๋‹ค์Œ ๊ฒฐ๊ณผ๋ฅผ ํ”Œ๋กœํŒ…ํ•˜๊ณ  ๋ณ€์ˆ˜์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์ธก ๋ชจ๋“œ ํŽ˜์ด์ง€์—์„œ ์ถ”๋ก  ์ธ์ˆ˜ ๋ฐ ๊ฒฐ๊ณผ ์ž‘์—…์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด์„ธ์š”.

    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)!
    
    1. ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ธ์ˆ˜๋ฅผ ํ™•์ธํ•˜๋ ค๋ฉด ํ”Œ๋กฏ ๋ฉ”์„œ๋“œ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.
  4. Now, use OpenCV to convert the 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. ๋‹ค๋ฅธ ์ด๋ฏธ์ง€ ํ™•์žฅ์ž๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    2. ์ธ๋ฑ์Šค์— ์žˆ๋Š” ๊ฐœ์ฒด๋งŒ 1 ๋ฅผ ๋ฐ˜ํ™˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  5. ๋งŒ๋“ค๊ธฐ SixelWriter ์ธ์Šคํ„ด์Šค๋ฅผ ์‚ฌ์šฉํ•œ ๋‹ค์Œ .draw() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ„ฐ๋ฏธ๋„์— ์ด๋ฏธ์ง€๋ฅผ ๊ทธ๋ฆฝ๋‹ˆ๋‹ค.

    from sixel import SixelWriter
    
    # Create sixel writer object
    w = SixelWriter()
    
    # Draw the sixel image in the terminal
    w.draw(mem_file)
    

์ถ”๋ก  ๊ฒฐ๊ณผ ์˜ˆ์‹œ

ํ„ฐ๋ฏธ๋„์—์„œ ์ด๋ฏธ์ง€ ๋ณด๊ธฐ

์œ„ํ—˜

์ด ์˜ˆ์‹œ๋ฅผ ๋™์˜์ƒ ๋˜๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜ 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. ๋‹ค๋ฅธ ์ด๋ฏธ์ง€ ํ™•์žฅ์ž๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  2. ์ธ๋ฑ์Šค์— ์žˆ๋Š” ๊ฐœ์ฒด๋งŒ 1 ๋ฅผ ๋ฐ˜ํ™˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  3. ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ธ์ˆ˜๋ฅผ ํ™•์ธํ•˜๋ ค๋ฉด ํ”Œ๋กฏ ๋ฉ”์„œ๋“œ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

ํŒ

๋‹ค์Œ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. clear ์„ ๋ˆŒ๋Ÿฌ ํ„ฐ๋ฏธ๋„์—์„œ ์ด๋ฏธ์ง€ ๋ณด๊ธฐ๋ฅผ "์ง€์šฐ์„ธ์š”".

์ž์ฃผ ๋ฌป๋Š” ์งˆ๋ฌธ

macOS ๋˜๋Š” Linux์˜ VSCode ํ„ฐ๋ฏธ๋„์—์„œ YOLO ์ถ”๋ก  ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ•˜๋‚˜์š”?

macOS ๋˜๋Š” Linux์˜ VSCode ํ„ฐ๋ฏธ๋„์—์„œ YOLO ์ถ”๋ก  ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ ค๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ๋”ฐ๋ฅด์„ธ์š”:

  1. ํ•„์š”ํ•œ VSCode ์„ค์ •์„ ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค:

    "terminal.integrated.enableImages": true
    "terminal.integrated.gpuAcceleration": "auto"
    
  2. ์‹์…€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค:

    pip install sixel
    
  3. YOLO ๋ชจ๋ธ์„ ๋กœ๋“œํ•˜๊ณ  ์ถ”๋ก ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค:

    from ultralytics import YOLO
    
    model = YOLO("yolo11n.pt")
    results = model.predict(source="path_to_image")
    plot = results[0].plot()
    
  4. ์ถ”๋ก  ๊ฒฐ๊ณผ ์ด๋ฏธ์ง€๋ฅผ ๋ฐ”์ดํŠธ ๋‹จ์œ„๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ํ„ฐ๋ฏธ๋„์— ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค:

    import io
    
    import cv2
    from sixel import SixelWriter
    
    im_bytes = cv2.imencode(".png", plot)[1].tobytes()
    mem_file = io.BytesIO(im_bytes)
    SixelWriter().draw(mem_file)
    

์ž์„ธํ•œ ๋‚ด์šฉ์€ ์˜ˆ์ธก ๋ชจ๋“œ ํŽ˜์ด์ง€๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

์‹์…€ ํ”„๋กœํ† ์ฝœ์ด Linux์™€ macOS์—์„œ๋งŒ ์ž‘๋™ํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?

์ด๋Ÿฌํ•œ ํ”Œ๋žซํผ์—๋Š” ์‹์…€ ๊ทธ๋ž˜ํ”ฝ๊ณผ ํ˜ธํ™˜๋˜๋Š” ๊ธฐ๋ณธ ํ„ฐ๋ฏธ๋„ ๊ธฐ๋Šฅ์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์‹์…€ ํ”„๋กœํ† ์ฝœ์€ ํ˜„์žฌ Linux์™€ macOS์—์„œ๋งŒ ์ง€์›๋ฉ๋‹ˆ๋‹ค. ์‹์…€์„ ์‚ฌ์šฉํ•˜๋Š” ํ„ฐ๋ฏธ๋„ ๊ทธ๋ž˜ํ”ฝ์— ๋Œ€ํ•œ Windows ์ง€์›์€ ์•„์ง ๊ฐœ๋ฐœ ์ค‘์ž…๋‹ˆ๋‹ค. Windows ํ˜ธํ™˜์„ฑ์— ๋Œ€ํ•œ ์—…๋ฐ์ดํŠธ๋Š” VSCode ์ด์Šˆ ์ƒํƒœ ๋ฐ ์„ค๋ช…์„œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

VSCode ํ„ฐ๋ฏธ๋„์—์„œ ์ด๋ฏธ์ง€๋ฅผ ํ‘œ์‹œํ•˜๋Š” ๋ฐ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์–ด๋–ป๊ฒŒ ํ•˜๋‚˜์š”?

6์…€์„ ์‚ฌ์šฉํ•˜์—ฌ VSCode ํ„ฐ๋ฏธ๋„์—์„œ ์ด๋ฏธ์ง€๋ฅผ ํ‘œ์‹œํ•˜๋Š” ๋ฐ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ์šฐ:

  1. VSCode์—์„œ ํ•„์š”ํ•œ ์„ค์ •์ด ํ™œ์„ฑํ™”๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค:

    "terminal.integrated.enableImages": true
    "terminal.integrated.gpuAcceleration": "auto"
    
  2. ์‹์…€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค:

    pip install sixel
    
  3. ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ ๋ณ€ํ™˜ ๋ฐ ํ”Œ๋กœํŒ… ์ฝ”๋“œ์— ์˜ค๋ฅ˜๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜์„ธ์š”. ์˜ˆ๋ฅผ ๋“ค์–ด

    import io
    
    import cv2
    from sixel import SixelWriter
    
    im_bytes = cv2.imencode(".png", plot)[1].tobytes()
    mem_file = io.BytesIO(im_bytes)
    SixelWriter().draw(mem_file)
    

๋ฌธ์ œ๊ฐ€ ์ง€์†๋˜๋ฉด VSCode ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ฐธ์กฐํ•˜๊ณ  ํ”Œ๋กฏ ๋ฉ”์„œ๋“œ ๋งค๊ฐœ๋ณ€์ˆ˜ ์„น์…˜์—์„œ ์ถ”๊ฐ€ ์ง€์นจ์„ ํ™•์ธํ•˜์„ธ์š”.

YOLO ์—์„œ 6์…€์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‹จ๋ง๊ธฐ์— ๋น„๋””์˜ค ์ถ”๋ก  ๊ฒฐ๊ณผ๋ฅผ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ๋‚˜์š”?

๋‹จ๋ง๊ธฐ์—์„œ 6์…€์„ ์‚ฌ์šฉํ•˜์—ฌ ๋™์˜์ƒ ์ถ”๋ก  ๊ฒฐ๊ณผ ๋˜๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜ GIF ํ”„๋ ˆ์ž„์„ ํ‘œ์‹œํ•˜๋Š” ๊ฒƒ์€ ํ˜„์žฌ ํ…Œ์ŠคํŠธ๋˜์ง€ ์•Š์•˜์œผ๋ฉฐ ์ง€์›๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ •์  ์ด๋ฏธ์ง€๋กœ ์‹œ์ž‘ํ•˜์—ฌ ํ˜ธํ™˜์„ฑ์„ ํ™•์ธํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์„ฑ๋Šฅ ์ œ์•ฝ์„ ์—ผ๋‘์— ๋‘๊ณ  ๋™์˜์ƒ ๊ฒฐ๊ณผ๋Š” ์‚ฌ์šฉ์ž ์ฑ…์ž„ํ•˜์— ์‹œ๋„ํ•˜์„ธ์š”. ์ถ”๋ก  ๊ฒฐ๊ณผ ํ”Œ๋กœํŒ…์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์˜ˆ์ธก ๋ชจ๋“œ ํŽ˜์ด์ง€๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

๊ด€๋ จ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ•˜๋‚˜์š”? python-sixel ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ?

๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋ ค๋ฉด python-sixel ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ:

  1. ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ๊ฐ€์ƒ ํ™˜๊ฒฝ์— ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์„ค์น˜๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค:

    pip install sixel
    
  2. ํ•„์š”ํ•œ Python ๋ฐ ์‹œ์Šคํ…œ ์ข…์†์„ฑ์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

  3. ์ถ”๊ฐ€ ๋ฌธ์„œ ๋ฐ ์ปค๋ฎค๋‹ˆํ‹ฐ ์ง€์›์€ python-sixel GitHub ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

  4. ์ฝ”๋“œ์— ์ž ์žฌ์ ์ธ ์˜ค๋ฅ˜๊ฐ€ ์žˆ๋Š”์ง€ ๋‹ค์‹œ ํ•œ ๋ฒˆ ํ™•์ธํ•˜์„ธ์š”. SixelWriter ๋ฐ ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ ๋ณ€ํ™˜ ๋‹จ๊ณ„.

YOLO ๋ชจ๋ธ ๋ฐ ์‹์…€ ํ†ตํ•ฉ ์ž‘์—…์— ๋Œ€ํ•œ ์ถ”๊ฐ€ ์ง€์›์€ ๋‚ด๋ณด๋‚ด๊ธฐ ๋ฐ ์˜ˆ์ธก ๋ชจ๋“œ ๋ฌธ์„œ ํŽ˜์ด์ง€๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.


๐Ÿ“… Created 7 months ago โœ๏ธ Updated 12 days ago

๋Œ“๊ธ€