Log in or register to post comments

Analysing colors of Image Target

July 17, 2013 - 3:21pm #1

Hi , I just saw this app colAR Mix which let you color image target and then changes the material of the 3d model based on the colors of image target : https://itunes.apple.com/us/app/colar-mix/id650645305?mt=8&ign-mpt=uo%3D4

It seems it's analysing the colors of image target , that's exactly what I wanted to some times ago but I didn't find a way to analyse the image and the colors of image target and somehow make my image target dynamic . any idea on how to do it ?

thanks

Analysing colors of Image Target

August 5, 2013 - 5:52pm #13

IIRC Elecman's UCS framework includes a shader that performs a camera patch extraction of the target using the camera frame. So there is no intermediate step to generate a screengrab.

Here is a similar approach using a fragment shader - https://developer.vuforia.com/resources/dev-guide/camera-target-patch

Analysing colors of Image Target

August 5, 2013 - 5:28pm #12

Thanks very much. I tested more and it seems that in RGB565 the app will just stop working , it won't even give me a simple debug when I swap format to RGB565  

I have an idea for an app which I'm researching for , I need to analyse image target as seen by device camera . I don't have any special formats in mind , I just need a format which gives me rgb color values  . I think the first three steps for analysing image target are:

  1. get screen shot of app
  2. crop image target from that screen shot
  3. de-warping the image target .

I discussed this with "elecman" in this forum : http://forum.unity3d.com/threads/108256-Unified-Coordinate-System-for-String-and-QCAR/page15   but he said we don't need to follow these steps , I didn't quite get what he meant though . 

Analysing colors of Image Target

August 5, 2013 - 3:10pm #11

I think that you're right, my test confirm what you're seeing.

Here is how to get the color components for a pixel ..

				Rect myRectTemp = new Rect(0,0,image.Width/2,image.Height/2);
				myTexture.pixelInset = myRectTemp; //myTexture is a public variable which holds a GUITexture gameobject
				Texture2D myTexture2D = new Texture2D(image.Width/2,image.Height/2);
				image.CopyToTexture(myTexture2D);
				
				Color pix_color = myTexture2D.GetPixel( image.Width/2,image.Height/2 );
				
				Debug.Log("Color components are "+ pix_color.r + ", "+ pix_color.g +", "+ pix_color.b +" : grayscale value = "+ pix_color.grayscale );
				
				myTexture.guiTexture.texture = myTexture2D;

 

The error on RGB565 is likely due to it being an unsupported format on that device. But I'm seeing the black grayscale as well, and will try to figure out why that is.

Which format(s) do you need to use for your app?

Analysing colors of Image Target

August 5, 2013 - 1:44pm #10

thanks . for RGB565 I've got size:352*288 , bufferSize:352*288 and stride : 704 . I don't think its GUItextures cause it's working in IDE and when I test it in playmode (in GRAYSCALE format ) . it's not working when I test it on my device . 

Analysing colors of Image Target

August 5, 2013 - 11:58am #9

Can you read the color values for those formats?  I'm wondering if this may be an issue w/ GUITextures.

Analysing colors of Image Target

August 4, 2013 - 6:36pm #8

Thanks , no I have just tested it on my Nexus S . the information about RGB565 format is shown correctly . and the frame rate seems to drop after I change my format to RGB565 but it doens't give me any feed from my camera . 

thanks again .

update : I tested the same code on my ipad and got the same result  .

Analysing colors of Image Target

August 4, 2013 - 5:57pm #7

Regarding the augmentation of a single frame:  You could accomplish something like that by capturing the frame + augmentation as a screen capture, and disabling the QCARBehaviour to deactivate the tracker and video background rendering.

Let me check on what might be the cause of the inability to obtain the pixel values for those formats on the device.

Have you tried the same experiment on multiple Android devices?

Analysing colors of Image Target

August 4, 2013 - 5:30pm #6

Hi , I was trying to do some experiments with this subject . I added these lines of codes after line 85 of your script . I tried to copy image to a guitexture to exactly see what image variable is holding . I succeeded on getting image variable content on my guitexture in unity webcam mode (which is when I switch to Grayscale format ) . but when I try it on my android device , It doesn't give me anything in RGB565 format and it just gives me a black image when it's in Grayscale . I'll appreciate if you can help me with this . here's my additional lines after line 85 of your script :

Rect myRectTemp = new Rect(0,0,image.Width/2,image.Height/2);
myTexture.pixelInset = myRectTemp; //myTexture is a public variable which holds a GUITexture gameobject
Texture2D myTexture2D = new Texture2D(image.Width/2,image.Height/2);
image.CopyToTexture(myTexture2D);
myTexture.guiTexture.texture = myTexture2D;

 

thanks

 

Analysing colors of Image Target

July 19, 2013 - 2:01pm #5

Thanks so much . getting to know these classes I wondered if it's possible to apply vuforia on a single frame of camera feed , I mean developing an app which doesn't augment the camera feed , but only augmenting one image captured by user . doing this we can avoid some noises and gain some adventages in some AR use cases . 

thanks

Analysing colors of Image Target

July 19, 2013 - 12:43pm #4

You'll need to extract what's known as a camera patch for the target, which is a de-warped texture of the 2D target image.

See: https://developer.vuforia.com/resources/dev-guide/camera-target-patch

and for Unity - https://developer.vuforia.com/forum/general-discussion/camera-pstch-unity-3d

Analysing colors of Image Target

July 19, 2013 - 12:34pm #3

Thanks very much , so I think this app captures camera feed and when the state of image target is TRACKED it saves the feed at that time and saves it as an image and then analyses that image , and then analyses that image for colors and maps the pixels of that image to the texture of 3d model to color it.
but there's still a question , when it saves the feed , image target is usually skewed ,and how can we differentiate our image target from other parts of our Camera feed in that image ?
thanks

Analysing colors of Image Target

July 17, 2013 - 5:29pm #2

Here is a script that shows how to register for image formats and to retrieve the camera image by format. You can then access the Pixels array for the image, which will be mapped to the selected format. - https://developer.vuforia.com/resources/api/unity/class_image

 

 

/*==============================================================================
            Copyright (c) 2010 QUALCOMM Incorporated.
            All Rights Reserved.
            Qualcomm Confidential and Proprietary
==============================================================================*/

using UnityEngine;
using System.Collections;

public class ImageTests : MonoBehaviour, ITrackerEventHandler
{
    private Image.PIXEL_FORMAT mCurrentFormat = Image.PIXEL_FORMAT.YUV;
    private bool mShouldReport = false;
	


    void Start()
    {
	
		
        QCARBehaviour qcarBehaviour = (QCARBehaviour) FindObjectOfType(typeof(QCARBehaviour));
        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackerEventHandler(this);
        }
    }
	
	public void OnInitialized(){
		
	}

    void OnGUI()
    {
		
		//GUILayout.Space(100);
		
		GUILayout.BeginArea( new Rect( 25, 100, 300, 500 ) );
		
        if (GUILayout.Button( "Swap Format" ) )
        {
            CameraDevice cam = CameraDevice.Instance;
            cam.SetFrameFormat(mCurrentFormat, false);

            switch (mCurrentFormat)
            {
                case Image.PIXEL_FORMAT.RGB565:
                    mCurrentFormat = Image.PIXEL_FORMAT.RGB888;
                    break;
                case Image.PIXEL_FORMAT.RGB888:
                    mCurrentFormat = Image.PIXEL_FORMAT.GRAYSCALE;
                    break;
                case Image.PIXEL_FORMAT.GRAYSCALE:
                    mCurrentFormat = Image.PIXEL_FORMAT.YUV;
                    break;
                case Image.PIXEL_FORMAT.YUV:
                    mCurrentFormat = Image.PIXEL_FORMAT.RGB565;
                    break;
            }

            cam.SetFrameFormat(mCurrentFormat, true);

            Debug.Log("Switching image format to " + mCurrentFormat);
            mShouldReport = true;
        }
		
		GUILayout.EndArea();
    }

    public void OnTrackablesUpdated()
    {
        if (mShouldReport)
        {
            CameraDevice cam = CameraDevice.Instance;
            Image image = cam.GetCameraImage(mCurrentFormat);
            if (image == null)
            {
                Debug.Log(mCurrentFormat + " image is not available yet");
            }
            else
            {
                string s = "\n" + mCurrentFormat + " image: \n";
                s += "size: " + image.Width + "x" + image.Height + "\n";
                s += "bufferSize: " + image.BufferWidth + "x" + image.BufferHeight + "\n";
                s += "stride: " + image.Stride;
                Debug.Log(s);
			

                mShouldReport = false;
            }
        }
    }
}

 

Log in or register to post comments