• 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
1
Question by RobertTPierce · Dec 26, 2019 at 10:32 PM · vrtexture2dimagequalityrobot

Image Quality Degradation between External Camera Stream and Display in Unity

Hey, guys,

I'm working on the Valkyrie project for NASA (Valkyrie / R5), and there's a few questions I'd like to ask you fine folks that relate to a single issue.

The Valkyrie's being fitted for virtual reality teleoperation, with two cameras outputting their respective feeds through ROS (https://www.ros.org/) as JPEG images at around ~ 5 Hz. We're using the ROS# Unity plugin in order to get the images from the cameras and display them in a virtual reality headset via Unity; I used an approach similar to this one: https://github.com/guiglass/StationaryStereoCamera in order to get two cameras looking at Plane objects which have the camera images rendered onto them via the material's SetTexture function.

The Problem:

The images as displayed on a Unity Plane are significantly degraded in quality from the original image stream from the cameras on the Valkyrie. I know that a texture's quality can be tuned using the import settings, but unlike in #447719, my textures are being generated at runtime, so there's no import setting window.

Valkyrie Picture from Unity -- terrible quality

(^ Bad quality texture from Unity.)

Valkyrie Picture from

(^ Good quality texture from the cameras themselves.)

Despite resizing the planes to match the aspect ratio of the 1328 x 1048 images, the weird pixelization effect persists.

The Question: I can't find any settings in the scripting API for Texture2D resembling the settings mentioned in [5]. Is there a way to do this sort of thing in another type of image/texture?

If ya'll want any more information about my setup, scene, scripts, or anything, just let me know either in the comments or in a PM. I couldn't include the package because it was too big at ~900 kB.

[2]: https://github.com/guiglass/StationaryStereoCamera

goodpicture-camerafeedjpg.jpg (150.5 kB)
badpicture-camerafeed-2019-12-26-104753.png (318.8 kB)
Comment
Add comment · Show 2
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 Casiell · Dec 26, 2019 at 11:29 PM 0
Share

Part of code responsible for generating texture would certainly not be a bad thing.

Also quick question: if you import this good quality image into Unity, does it look as bad as the generated one?

avatar image RobertTPierce · Dec 27, 2019 at 03:55 PM 0
Share

In response to @Casiell, here's the script for generating the texture from an inco$$anonymous$$g array of bytes.

 public sealed class ValkyrieCameraSubscriber_3D : UnitySubscriber<$$anonymous$$essageTypes.Sensor.CompressedImage>
     {
 
         public $$anonymous$$eshRenderer meshRenderer;
 
         private Texture2D texture2D;
         private byte[] imageData;
         private bool is$$anonymous$$essageReceived;
 
         protected override void Start()
         {
             
             base.Start();
 
             texture2D = new Texture2D(Screen.height, Screen.width);
             meshRenderer.material = new $$anonymous$$aterial(Shader.Find("Unlit/Texture"));
 
         }
 
         private void Update()
         {
             if (this.is$$anonymous$$essageReceived)
             {
 
                 Process$$anonymous$$essage();
             }
         }
 
 
         private void Process$$anonymous$$essage()
         {
 
             texture2D.LoadImage(imageData);
             texture2D.Apply();
 
             meshRenderer.material.SetTexture("_$$anonymous$$ainTex", texture2D);
             is$$anonymous$$essageReceived = false;
         }
 
         protected override void Receive$$anonymous$$essage($$anonymous$$essageTypes.Sensor.CompressedImage image)
         {
             imageData = image.data;
             is$$anonymous$$essageReceived = true;
         }
     }


Receive$$anonymous$$essage is a callback function that is invoked each time a ROS message comes through. Upon receipt of a CompressedImage, the imageData variable is updated with the image bytes. Then, Process$$anonymous$$essage is called, which invokes LoadImage on the Texture2D object to get the image data in there, then it uses Apply() to ensure that it'll display right (the documentation told me this step was necessary). Then we set the plane's texture to this generated texture.

As for the importation of the good quality image, it appears that it retains excellent sharpness if I import a snapshot of the camera feed like a regular texture. alt text

good-imported-quality-2019-12-27-095311.jpg (149.5 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by RobertTPierce · Dec 27, 2019 at 10:04 PM

@Casiell

I just found a way to fix my problem. There are two RenderTextures in my scene that were hooked into the cameras for each eye. The two RenderTextures were only 256x256, so the 1328x1048 camera feed image was being stuffed into a texture of that size. I solved it by making the RenderTextures bigger than the incoming images.

I'll consider this question answered (by myself).

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.

Follow this Question

Answers Answers and Comments

154 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Display an image in native resolution of a Head Mounted Display 0 Answers

!texture.texture error 0 Answers

Asset Texture Resolution VR 0 Answers

[Android+Eclipse]Get album image from mp3 file 0 Answers

how to release GPU RAM after taking a photo. 1 Answer


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