• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by RustemKamun · Mar 15, 2011 at 11:34 AM · opencvemgucv

EmguCv inside Unity

Hey guys, I am using EmguCv wrapper inside Unity to develop some game. Right now, Iam confronted with problem of CONVERTATION IplImage(Image) to Texture2D(unity texture). I've read a lot of posts before and implemented one idea: Unfortunately it workes only for histogram drawing. What I've done there: Firstly, I convert Image to Image, then I got ManagedArray of bytes from Image and set the data to newly created Texture2D:

CvInvoke.cvCvtColor(img.Ptr, copy_img, COLOR_CONVERSION.CV_BGR2RGBA); Array bytes = copy_img.ManagedArray; int h = bytes.GetLength(0); int w = bytes.GetLength(1);

for (int i = 0; i

t.SetPixel(y, x, new UnityEngine.Color((float)r, (float)g, (float)b, (float)a));

} }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CeciSach · Feb 25, 2012 at 10:18 PM 0
Share

Hi, I want to integrate EmguCv in Unity, but I don't know how to do it. I'm new to this all, could you give me a hand? Thanks.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Oct 21, 2011 at 10:32 PM

http://unity3d.qatohost.com/questions/23450/mono-and-missing-types-using-external-library.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by canert · Jan 10, 2015 at 11:33 AM

Maybe, you can use this code block for taking image to texture..

 using UnityEngine;
 using System.Collections;
 using Emgu.CV;
 using Emgu.CV.Util;
 using Emgu.CV.CvEnum;
 using Emgu.CV.Structure;
 using System.IO;
 
     private Capture cap;
     Texture2D camera;
     
     void Start()
     {
         cap = new Capture(0);
     }
     
     
     void Update()
     {
         using (Image<Bgr, byte> nextFrame = cap.QueryFrame())
         {
             if (nextFrame != null)
             { 
                 System.Drawing.Bitmap bitmapCurrentFrame = nextFrame.ToBitmap ();
                 MemoryStream m = new MemoryStream ();
                 bitmapCurrentFrame.Save (m, bitmapCurrentFrame.RawFormat);
 
                 if(camera!=null){
                     GameObject.Destroy(camera);
                 }
                 camera = new Texture2D (400, 400);
                 
                 camera.LoadImage (m.ToArray ());
                 renderer.material.mainTexture = camera;
             }
         }
         
     }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

OpenCV and Android with Unity3D 1 Answer

Plugins on OSX (OpenCV and EmguCV) 2 Answers

LED Tracking with Unity & emguCV 1 Answer

C#, EmguCv, opencv and mavericks 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges