- Home /
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);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612002523im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
import video from camera 3 Answers
Sending Unity Camera Video to Python for OpenCV 1 Answer
Setting background texture dynamically 0 Answers
How to use opencv face detection with ARCore camera? 0 Answers