samedi 15 mars 2025

YOLO and Redbol

YOLO (You Only Look Once) is a wonderful tool for object detection and image segmentation (https://docs.ultralytics.com/).
Of course, this works very well with Python.  You'll find here a very clear documentation (https://pyimagesearch.com/2025/01/13/getting-started-with-yolo11/). 
But YOLO also offers a CLI mode that can be used with Rebol3 or Red.
With Rebol3 we use the opencv module made by Oldes.  The result with articulations detection in around 1 sec!


And for Red: just Red language functions.

#! /usr/local/bin/red-view
Red [
    Needs: View
    Author: "ldci"
]

appDir: system/options/path
change-dir appDir
imageFile: ""
iSize: 320x240
margins: 5x5
isFile?: false
tasks: ["segment" "pose" "detect"] ;--("obb" "classify" not yet)
modes: ["predict" "track" ];--("benchmark"  "train"  "export" "val" not yet)
models: ["yolo11n-seg.pt" "yolo11n-pose.pt" "yolo11n.pt" "yolov9c-seg.pt" "yolov8n-seg.pt"]
source: ""
task: tasks/1
mode: modes/1
model: rejoin ["models/" models/1]
loadImage:  does [
isFile?: false
tmpFile: request-file
unless none? tmpFile [
canvas1/image: load to-red-file tmpFile
canvas2/image: none
s: split-path tmpFile
imageFile: s/2
source: rejoin ["images/" imageFile]
sb/text: source
isFile?: true
]
]
runYOLO: does [
if isFile? [
canvas2/image: none
clear retStr/text
results: %results.txt
if exists? results [delete results]
prog: rejoin ["yolo " task " " mode " model=" model" " "source=" source]
sb/text: prog
do-events/no-wait
tt:  dt [ret: call/wait/shell/output prog results]
if ret = 0 [
retStr/text: f: read results
f: find f "runs" ;--get directory
s: split f "" ;--get complete directory
destination: rejoin [s/1 "/" imageFile]
canvas2/image: load to-red-file destination]
sb/text: rejoin ["Result: " destination "  in " round/to (tt/3) 0.01 " sec"]
]
]
mainWin: layout [
title "Red and YOLO"
origin margins space margins
base 40x22 snow "Model" 
dp1: drop-down 120 data models select 1
on-change [model: rejoin ["models/" pick face/data face/selected]]
base 40x22 snow "Tasks" 
dp2: drop-down 80 data tasks select 1
on-change [task: pick face/data face/selected]
base 40x22 snow "Mode"  
dp3: drop-down 80 data modes select 1 
on-change [mode: pick face/data face/selected]
button "Load Image" [loadImage]
button "Run YOLO" [runYOLO]
pad 280x0 button 50 "Quit" [quit]
return
canvas1: base iSize
canvas2: base iSize
retStr: area iSize wrap
return
sb: field 645
]
view mainWin


Nice job YOLO.





Aucun commentaire:

Enregistrer un commentaire