mariorancic
Topic Author
Posts: 23
Joined: 20 Jul 2019, 22:50

barcode scanner

08 Dec 2021, 21:04

Is it possible to integrate some of bar code scanner sdk's with NoesisGui on the phones and especially with managed NoesisGui
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: barcode scanner

09 Dec 2021, 10:26

What exactly do you need from NoesisGUI for that? You can show any UI on top of the camera video, and later you can show an image of the scanned barcode so there should be no problem.
 
mariorancic
Topic Author
Posts: 23
Joined: 20 Jul 2019, 22:50

Re: barcode scanner

10 Dec 2021, 10:43

What exactly I want to do is to show the drawing of the armature bending and because I did it in WPF my idea was to show it with the help of NoesisGUI after barcode scanning on the phone. And I can show the drawing with NoesisGUI with almost no code change from WPF. But from what I understood from you, your idea is that I build my own barcode scanning component which I am not planning to do. I would like to do it with help of some known cross platform components like ZXing. And my question is , how even to access the phone camera with NoesisGUI. Do I have to do it in platform specific project like in iOS. And do you have code example how to access the camera in iOS platform specific project.
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: barcode scanner

10 Dec 2021, 11:08

Maybe I didn't explain myself correctly. I meant that NoesisGUI has nothing to do with barcode scanning, we don't provide any API for that or for interacting with the phone, that should be totally done by the application logic and we can't help with that. NoesisGUI can only be responsible for the rendering of the UI elements of your application/game.
 
mariorancic
Topic Author
Posts: 23
Joined: 20 Jul 2019, 22:50

Re: barcode scanner

10 Dec 2021, 14:54

I know that, that is exactly my problem. The rendering and reusability and performance in NoesisGUI is superior to any other cross platform, my problem is how to integrate it with some other logic. I saw integration examples with c++, but how it works with with NoesisGUI .net SDK. Can I directly from .net projects where I use NoesisGUI integrate some other NuGet package for example. Thats my question
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: barcode scanner

10 Dec 2021, 21:24

Noesis is not an application framework like the rest of alternatives. We are a minimalist UI framework, platform agnostic. We don't offer API for non UI tasks, like camera, or specific APIs for Android or iOS. So, you are in charge of doing that, using whatever technology you decide.

On top of our core technology, we have an application framework, but it is minimal and created just for our samples. For example, download our HelloWorld application for C# and see how we are organizing everything. You can follow a similar approach or just use your own one, with or without nugets.

Hope this clarifies something : )
 
mariorancic
Topic Author
Posts: 23
Joined: 20 Jul 2019, 22:50

Re: barcode scanner

10 Dec 2021, 23:47

Yes it is. Even though you called it minimalistic your UI framework is amazing and I think your approach is best becaue it is platform agnostic and does not depend on native controls. Yes, I wanted to mix NoesisGUI XAML with some other technologies but it seems this will not be possible. But for my needs I just need NoesisGUI UI and externall barcode scanner component that I ll call somehow from the code. If I get into troubles of showing external component on top or above NoesigGUI I ll be free to ask again :). Thx for all the answers
 
mariorancic
Topic Author
Posts: 23
Joined: 20 Jul 2019, 22:50

Re: barcode scanner

03 Jan 2022, 15:49

I have a problem to render the camera. In Xamarin.IOS the camera has to be rendered to UIImageView object.
The whole idea I grabbed from here: https://docs.microsoft.com/en-us/xamari ... a-controls
I am sending below all code that compiles except in the line before last line where of course I could not use UIimageView object. I am offering to pay to you Sergio or Jesus or anybody else who can fix this problem with rendering camera because it is integration issue but I do not know how to fix it and i am desperate because of this I could not use everything else great from Noesis. Here is the code:
// Create a new capture session
Session = new AVCaptureSession ();
Session.SessionPreset = AVCaptureSession.PresetMedium;

// Create a device input
CaptureDevice = AVCaptureDevice.DefaultDeviceWithMediaType (AVMediaType.Video);
if (CaptureDevice == null)
    throw new Exception ("Video recording not supported on this device");

// Prepare device for configuration
if (!CaptureDevice.LockForConfiguration (out Error)) {
    // There has been an issue, abort
    Console.WriteLine ("Error: {0}", Error.LocalizedDescription);
    CaptureDevice.UnlockForConfiguration ();
    return;
}

// Configure stream for 15 frames per second (fps)
CaptureDevice.ActiveVideoMinFrameDuration = new CMTime (1, 15);

// Unlock configuration
CaptureDevice.UnlockForConfiguration ();

// Get input from capture device
Input = AVCaptureDeviceInput.FromDevice (CaptureDevice);
if (Input == null) {
    // Error, report and abort
    Console.WriteLine ("Unable to gain input from capture device.");
    CameraAvailable = false;
    return;
}

// Attach input to session
Session.AddInput (Input);

// Create a new output
var output = new AVCaptureVideoDataOutput ();
var settings = new AVVideoSettingsUncompressed ();
settings.PixelFormatType = CVPixelFormatType.CV32BGRA;
output.WeakVideoSettings = settings.Dictionary;

// Configure and attach to the output to the session
Queue = new DispatchQueue ("ManCamQueue");
Recorder = new OutputRecorder ();
output.SetSampleBufferDelegate (Recorder, Queue);
Session.AddOutput (output);

// Configure and attach a still image output for bracketed capture
StillImageOutput = new AVCaptureStillImageOutput ();
var dict = new NSMutableDictionary ();
dict [AVVideo.CodecKey] = new NSNumber ((int)AVVideoCodec.JPEG);
Session.AddOutput (StillImageOutput);

// Let tabs know that a camera is available
CameraAvailable = true;

// this line does not compile
Recorder.DisplayView = CameraView;

Session.StartRunning();
Actually this class is critical to integrate:
using System;
using Foundation;
using UIKit;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using AVFoundation;
using CoreVideo;
using CoreMedia;
using CoreGraphics;

namespace ManualCameraControls
{
	/// <summary>
	/// Helper class that pulls an image from the sample buffer and displays it in the <c>UIImageView</c>
	/// that it has been attached to.
	/// </summary>
	public class OutputRecorder : AVCaptureVideoDataOutputSampleBufferDelegate
	{
		#region Computed Properties
		/// <summary>
		/// Gets or sets the display view.
		/// </summary>
		/// <value>The display view.</value>
		public UIImageView DisplayView { get; set; }
		#endregion

		#region Constructors
		/// <summary>
		/// Initializes a new instance of the <see cref="ManualCameraControls.OutputRecorder"/> class.
		/// </summary>
		public OutputRecorder ()
		{

		}
		#endregion

		#region Private Methods
		/// <summary>
		/// Gets a single image frame from sample buffer.
		/// </summary>
		/// <returns>The image from sample buffer.</returns>
		/// <param name="sampleBuffer">Sample buffer.</param>
		private UIImage GetImageFromSampleBuffer(CMSampleBuffer sampleBuffer) {

			// Get a pixel buffer from the sample buffer
			using (var pixelBuffer = sampleBuffer.GetImageBuffer () as CVPixelBuffer) {
				// Lock the base address
				pixelBuffer.Lock (CVOptionFlags.None);

				// Prepare to decode buffer
				var flags = CGBitmapFlags.PremultipliedFirst | CGBitmapFlags.ByteOrder32Little;

				// Decode buffer - Create a new colorspace
				using (var cs = CGColorSpace.CreateDeviceRGB ()) {

					// Create new context from buffer
					using (var context = new CGBitmapContext (pixelBuffer.BaseAddress,
						                     pixelBuffer.Width,
						                     pixelBuffer.Height,
						                     8,
						                     pixelBuffer.BytesPerRow,
						                     cs,
						                     (CGImageAlphaInfo)flags)) {

						// Get the image from the context
						using (var cgImage = context.ToImage ()) {

							// Unlock and return image
							pixelBuffer.Unlock (CVOptionFlags.None);
							return UIImage.FromImage (cgImage);
						}
					}
				}
			}
		}
		#endregion

		#region Override Methods
		/// <Docs>The capture output on which the frame was captured.</Docs>
		/// <param name="connection">The connection on which the video frame was received.</param>
		/// <remarks>Unless you need to keep the buffer for longer, you must call
		///  Dispose() on the sampleBuffer before returning. The system
		///  has a limited pool of video frames, and once it runs out of
		///  those buffers, the system will stop calling this method
		///  until the buffers are released.</remarks>
		/// <summary>
		/// Dids the output sample buffer.
		/// </summary>
		/// <param name="captureOutput">Capture output.</param>
		/// <param name="sampleBuffer">Sample buffer.</param>
		public override void DidOutputSampleBuffer (AVCaptureOutput captureOutput, CMSampleBuffer sampleBuffer, AVCaptureConnection connection)
		{
			// Trap all errors
			try {
				// Grab an image from the buffer
				var image = GetImageFromSampleBuffer(sampleBuffer);

				// Display the image
				if (DisplayView !=null) {
					DisplayView.BeginInvokeOnMainThread(() => {
						// Set the image
						var oldImg = DisplayView.Image;
						oldImg?.Dispose ();

						DisplayView.Image = image;

						// Rotate image to the correct display orientation
						DisplayView.Transform = CGAffineTransform.MakeRotation((float)Math.PI/2);
					});
				}

				// IMPORTANT: You must release the buffer because AVFoundation has a fixed number
				// of buffers and will stop delivering frames if it runs out.
				sampleBuffer.Dispose();
			}
			catch(Exception e) {
				// Report error
				Console.WriteLine ("Error sampling buffer: {0}", e.Message);
			}
		}
		#endregion
	}
}
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: barcode scanner

03 Jan 2022, 18:10

You need a GPU texture handle. If you have that, rendering with Noesis is trivial. This is not related to Noesis so probably you will get more help asking in Xamarin forums.
 
mariorancic
Topic Author
Posts: 23
Joined: 20 Jul 2019, 22:50

Re: barcode scanner

03 Jan 2022, 22:58

Thx Jesus. Does maybe playing with this component be good direction:
https://github.com/xamarin/XamarinCompo ... S/GPUImage

Who is online

Users browsing this forum: Bing [Bot] and 89 guests