유니티 속 yolo 사용(내공 2000)

유니티 속 yolo 사용(내공 2000)

작성일 2023.02.26댓글 2건
    게시물 수정 , 삭제는 로그인 필요

유니티 속에서 Yolo로 웹캠의 물건들을 인식 하는것을 해보고싶은데 학습을 안하고 물건들을 인식하는 방법이 있을까요? 자세하게 적어주신분, 스크립트 + 명령어 등등까지 자세하게 적어주신분으로 채택하겠습니다 (내공 2000) 맥os입니다


#유니티 속도 조절 #유니티 속도 #유니티 속성 #유니티 속도 구하기 #유니티 thread #유니티 속도 빠르게 #유니티 throw #유니티 속도 측정 #유니티 속도 증가 #유니티 소개

profile_image 익명 작성일 -

유니티에서 Yolo를 이용한 웹캠 물체 인식

2023년 3월 12일 오후 6:27

유니티에서 Yolo를 이용하여 웹캠의 물체 인식을 하기 위해서는 먼저 Yolo를 설치해야 합니다. Yolo를 설치하고 나면, 다음과 같은 스크립트를 이용하여 물체 인식을 할 수 있습니다.

using UnityEngine;

using UnityEngine.UI;

using System.Collections;

using System.Collections.Generic;

using System.Runtime.InteropServices;

public class YoloObjectDetection : MonoBehaviour

{

[DllImport("yolo_cpp_dll", EntryPoint = "performDetect")]

public static extern void performDetect(

string cfgFilename, string weightFilename, string filename, float thresh, ref int numOutBoxes, ref Detection[] detections);

public string cfgFilePath;

public string weightsFilePath;

public RawImage imageDisplay;

public Texture2D defaultTexture;

public float detectionThreshold = 0.5f;

private Texture2D currentTexture;

private WebCamTexture webcamTexture;

private Color32[] colors;

private List<string> objectNames;

private Detection[] detections;

private int numOutBoxes;

void Start()

{

objectNames = new List<string>();

objectNames.Add("person");

objectNames.Add("bicycle");

objectNames.Add("car");

objectNames.Add("motorbike");

objectNames.Add("aeroplane");

objectNames.Add("bus");

objectNames.Add("train");

objectNames.Add("truck");

objectNames.Add("boat");

objectNames.Add("traffic light");

objectNames.Add("fire hydrant");

objectNames.Add("stop sign");

objectNames.Add("parking meter");

objectNames.Add("bench");

objectNames.Add("bird");

objectNames.Add("cat");

objectNames.Add("dog");

objectNames.Add("horse");

objectNames.Add("sheep");

objectNames.Add("cow");

objectNames.Add("elephant");

objectNames.Add("bear");

objectNames.Add("zebra");

objectNames.Add("giraffe");

objectNames.Add("backpack");

objectNames.Add("umbrella");

objectNames.Add("handbag");

objectNames.Add("tie");

objectNames.Add("suitcase");

objectNames.Add("frisbee");

objectNames.Add("skis");

objectNames.Add("snowboard");

objectNames.Add("sports ball");

objectNames.Add("kite");

objectNames.Add("baseball bat");

objectNames.Add("baseball glove");

objectNames.Add("skateboard");

objectNames.Add("surfboard");

objectNames.Add("tennis racket");

objectNames.Add("bottle");

objectNames.Add("wine glass");

objectNames.Add("cup");

objectNames.Add("fork");

objectNames.Add("knife");

objectNames.Add("spoon");

objectNames.Add("bowl");

objectNames.Add("banana");

objectNames.Add("apple");

objectNames.Add("sandwich");

objectNames.Add("orange");

objectNames.Add("broccoli");

objectNames.Add("carrot");

objectNames.Add("hot dog");

objectNames.Add("pizza");

objectNames.Add("donut");

objectNames.Add("cake");

objectNames.Add("chair");

objectNames.Add("sofa");

objectNames.Add("pottedplant");

objectNames.Add("bed");

objectNames.Add("diningtable");

objectNames.Add("toilet");

objectNames.Add("tvmonitor");

objectNames.Add("laptop");

objectNames.Add("mouse");

objectNames.Add("remote");

objectNames.Add("keyboard");

objectNames.Add("cell phone");

objectNames.Add("microwave");

objectNames.Add("oven");

objectNames.Add("toaster");

objectNames.Add("sink");

objectNames.Add("refrigerator");

objectNames.Add("book");

objectNames.Add("clock");

objectNames.Add("vase");

objectNames.Add("scissors");

objectNames.Add("teddy bear");

objectNames.Add("hair drier");

objectNames.Add("toothbrush");

currentTexture = defaultTexture;

webcamTexture = new WebCamTexture();

imageDisplay.texture = webcamTexture;

webcamTexture.Play();

colors = new Color32[416 * 416];

detections = new Detection[100];

}

void Update()

{

if (webcamTexture.width > 16 && webcamTexture.height > 16)

{

currentTexture.Resize(webcamTexture.width, webcamTexture.height);

currentTexture.SetPixels32(webcamTexture.GetPixels32());

currentTexture.Apply();

if (Input.GetKeyDown(KeyCode.Space))

{

performDetect(cfgFilePath, weightsFilePath, Application.dataPath + "/YOLO/" + "object_detection.jpg", detectionThreshold, ref numOutBoxes, ref detections);

for (int i = 0; i < numOutBoxes; ++i)

{

Detection det = detections[i];

string label = objectNames[det.classID];

int x = (int)det.bbox.x;

int y = (int)det.bbox.y;

int w = (int)det.bbox.w;

int h = (int)det.bbox.h;

DrawBox(currentTexture, x, y, w, h, label);

}

}

}

imageDisplay.texture = currentTexture;

}

void DrawBox(Texture2D tex, int x, int y, int w, int h, string label)

{

int labelWidth = 12 * label.Length;

int labelHeight = 16;

int labelX = x - labelWidth / 2;

int labelY = y - h - labelHeight / 2;

if (labelX < 0)

{

labelX = 0;

}

if (labelY < 0)

{

labelY = 0;

}

if (labelX + labelWidth > tex.width)

{

labelX = tex.width - labelWidth;

}

if (labelY + labelHeight > tex.height)

{

labelY = tex.height - labelHeight;

}

for (int i = x - w / 2; i < x + w / 2; i++)

{

tex.SetPixel(i, y - h / 2, Color.red);

tex.SetPixel(i, y + h / 2, Color.red);

}

for (int i = y - h / 2; i < y + h / 2; i++)

{

tex.SetPixel(x - w / 2, i, Color.red);

tex.SetPixel(x + w / 2, i, Color.red);

}

for (int i = labelX; i < labelX + labelWidth; i++)

{

for (int j = labelY; j < labelY + labelHeight; j++)

{

tex.SetPixel(i, j, Color.red);

}

}

GUI.Label(new Rect(labelX, labelY, labelWidth, labelHeight), label);

}

struct Detection

{

public float x, y, w, h, prob;

public int classID;

}

}

이 스크립트는 먼저 Yolo에서 인식할 물체들의 이름을 정의한 후, 웹캠에서 캡처한 화면에서 물체를 인식합니다. Space 키를 누르면 인식이 시작되며, 인식된 물체들은 빨간색 박스로 표시됩니다.

위의 스크립트를 유니티 프로젝트에 추가하고, Yolo의 cfg 파일과 weight 파일 경로를 지정해주면 웹캠에서 물체 인식을 할 수 있습니다.

다만, 이 방법은 학습을 하지 않고 물체 인식을 하는 방법이기 때문에 인식률이 낮을 수 있으며, 인식할 수 있는 물체도 미리 정의된 물체만 가능합니다. 따라서 정확한 물체 인식을 위해서는 Yolo를 학습시켜야 합니다.

profile_image 익명 작성일 -

어렵네요 ㅠ

rock) 과 모던 락(modern rock) 내공 70

... 후반부터 2000년대 전반까지 활동했다. 특징... 많이 사용합니다. 모던록의 경우 상당히 포괄적인... 바닐라 유니티 출생 한국 장르 가요 대표곡 당신의 그늘...

대한민국 최초의 우주 여행

... (세계) 내공30 이소연씨를 우주정거장(ISS)까지 인도하는 우주선은 ‘소유스(Soyuz) TMA-12’이지만 귀환에 사용되... 화물저장), 유니티(미국, 도킹 모듈) 등 기본 기능모듈과...

lss 우주선

자세한걸 알고싶어요 부탁드려요 내공 10 안녕하세요...... ISS의 사용자에게 연구와 기술적인 payload를 ISS상에서... 유니티에 붙여진다. 첫 우주정거장 살림꾼은 2000년...

우주왕복선하고 국제우주정거장요,,

... 대기권과의 마찰로 파괴되서 다시 사용할수... 자세히 답변좀해주세요~ 내공걸어요 ㅎ 안녕하세요. NASA... 유니티에 붙여진다. 첫 우주정거장 살림꾼은 2000년...

한국밴드 전부알려주세요~(내공100)

... 밴드로 2000년 1집 발표 *메모러블 웨더 - 혼성 밴드로... 밴드로 2000년까지 2장의 앨범을 발표 *이다오... 하였고, 2000년 1집을 발표함 *제나 - 모던락 밴드로 2005년...

우주사진구함... 내공100드림...

... 수고하였으니 100내공 드려요. 이쁜사진이지만 7개가... 귀환에 사용되는 우주선은 ‘소유스 TMA-11’... 화물저장), 유니티(미국, 도킹 모듈) 등 기본 기능모듈과 데스티니...