Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by 1994tymek · Sep 04, 2015 at 12:58 PM · cameratexture2dframeopencvquery

QueryFrame changes resolution of camera

Hi, I want to integrate Basler camera with Unity through opencvsharp.

When I open my camera through Basler's software = Pylon the resolution is 1280x960. But I want to convert frames from camera to texture2d. I wrote some code that convert iplimage to textute2d, but i saw that queryFrame (which allows me to get iplimage format) changes resolution of my camera to 640x480. Image isn't resized but cut. It's only 1/4 of primary image.

I can also add that camera uses USB 3.0 interface, and i have only USB 2.0 but my colleague checked this with USB 3.0 and it's the same.

So have someone any ideas why queryframe do this? And why my conversion is so slow? Thank you in advance. using UnityEngine; using System; using System.Runtime.InteropServices; using OpenCvSharp;

 public class przyklad: MonoBehaviour {
     
     public int klatka_width = 1280;
     public int klatka_height = 960;
     
     protected Texture2D m_Texture;
     protected Color[] m_Pixels;
     protected GCHandle m_PixelsHandle;
     
     public CvCapture cap;
     public IntPtr image_ptr;
     public GCHandle image_ptrHandle;
     
     
     void setupImageUpdate()
     {
         // Create texture that will be updated in the function
         m_Texture = new Texture2D (klatka_width, klatka_height, TextureFormat.RGBA32, false);
         // Create texture that will be updated in the function
         m_Pixels = m_Texture.GetPixels (0);
         
         // starts camera
         cap = CvCapture.FromCamera (0);
         
         
         // Assign texture to the renderer
         if (renderer)
             renderer.material.mainTexture = m_Texture;
         // or gui texture
         else if (GetComponent(typeof(GUITexture)))
         {
             GUITexture gui = GetComponent(typeof(GUITexture)) as GUITexture;
             gui.texture = m_Texture;
         }
         else
         {
             Debug.Log("Game object has no renderer or gui texture to assign the generated texture to!");
         }
     }
     
     
     void IplImageToTexture2D (IplImage displayImg, int imWidth, int imHeight, Texture2D new_Text)
     {
         for (int i = 0; i < imHeight; i++)
         {
             for (int j = 0; j < imWidth; j++)
             {
                 byte b = (byte)displayImg[i, j].Val0;
                 byte g = (byte)displayImg[i, j].Val1;
                 byte r = (byte)displayImg[i, j].Val2;
                 Color32 color = new Color32(r , g , b, 1);
                 new_Text.SetPixel(j, imHeight - i - 1, color);
                 
             }
         }
         new_Text.Apply();
         renderer.material.mainTexture = new_Text;
     }
     
     
     // Use this for initialization
     void Start () 
     {
         setupImageUpdate();
 
     }
 
     
     // Update is called once per frame
     void Update () 
     {
         
         IplImage klatka = cap.QueryFrame();
         // shows me resolution of camera
         Debug.Log (klatka.Width);
         Debug.Log (klatka.Height);
         IplImageToTexture2D (klatka, klatka_width, klatka_height, m_Texture);
         // 
         float t = Time.deltaTime;
         Debug.Log (t);
     }
 }
 
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

import video from camera 3 Answers

Sending Unity Camera Video to Python for OpenCV 1 Answer

Specifying a camera using ScreenShotMovie and changing capture rate while not affecting playback rate 1 Answer

Setting background texture dynamically 0 Answers

How to use opencv face detection with ARCore camera? 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