Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to setup ZXing?

Discussion in 'Scripting' started by Oribow, Oct 11, 2015.

  1. Oribow

    Oribow

    Joined:
    Nov 9, 2012
    Posts:
    38
    Hi,
    I want to use the ZXing libarys to detected Qr codes from a mobile camera. The problem is, that I cant get ZXing to accept the WebCamTexture. My current setup gives me an Array out of bounds exception at CalculateLuminanceRGB24. Does anybody previously worked with ZXing and can show me how to set this up?
    Any Help will be appreciated.

    Code (CSharp):
    1. IntPtr pointer = webCamTex.GetNativeTexturePtr();
    2.         texture2d.UpdateExternalTexture(pointer);
    3.         Result result = multiFormatReader.decode(new BinaryBitmap( new HybridBinarizer( new RGBLuminanceSource(texture2d.EncodeToPNG(),texture2d.width-1,texture2d.height-1))));
     
  2. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,960
    Hi @Oribow . This hack:
    Code (CSharp):
    1. texture2D.UpdateExternalTexture(webCamTexture.GetNativeTexturePtr());
    2. texture2D.EncodeToPNG();
    Won't work at all. You must copy the webcam's data to the texture2D like so:
    Code (CSharp):
    1. texture2D.SetPixels32(webCamTexture.GetPixels32());
    2. texture2D.Apply()
    then send it to ZXing. But here is a much better alternative.

    Check out NatCam. It eliminates the need for ZXing's slow performance on iOS and Android. It supports 8 different barcode formats.
     
    ina and Oribow like this.
  3. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,059
    Does NatCam still support barcodes
     
  4. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,960
    Not anymore. We deprecated this functionality a few releases ago as we wanted to slim down the API to just camera control.
     
  5. Oribow

    Oribow

    Joined:
    Nov 9, 2012
    Posts:
    38
    @Lanre I appreciate your input. After 3 years of waiting someone has finally answered my question. Nice callback to my beginner years as a programmer. ;)
     
  6. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,960
    Lol that's quite a while. What do you work on now?