SDK 2014 R5 .. first issue?

It seems USB Camera doesn’t work anymore. I’ve double checked DLL and are correctly set to 4.3.6.

The exception is in GHI.Hardware.dll but called from Camera_43.cs during event PictureCaptured … I hadn’t checked ConvertToFile in other context for the moment.


        void camera_PictureCaptured(Camera sender, GT.Picture e)
        {
            Debug.Print("Image ready!");
            mybitmap = e.PictureData;
            fl_pictready = true;
        }



EDIT: The same code works fine in R4

@ dobova - I was able to reproduce the issue. In this SDK we changed how we handle bitmaps in our libraries quite a bit to greatly improve performance. Regretfully, I made a small mistake in the ConvertToFile and Convert functions. We’re looking into providing a fix for this, but don’t have anything at this time.

As far as we can tell so far, those two functions are only used by the DisplayN18 on non-cerb boards and the TakePicture functionality of the camera. In my tests, StreamStreaming and BitmapStreamed in the Camera still work fine. You could work around your specific issue by streaming instead and stopping as soon as you receive a bitmap.

Thank you John for the info.
Do you think that direct use of the converttofile function fail in the same way?

@ dobova - I believe any use of either function will fail.

@ John - arghh, I will wait for a fix … :’(

@ dobova - While it is not ideal and is quite slow when compared to their native versions, here are some rough C# versions of those functions. The Mainboard.NativeBitmapConverter line is important because it allows the N18 to function, though slowly, on non-cerb boards. If you still wish to use the TakePicture method of the Camera, you will need to modify the driver and change line 192 to use this temporary ConvertToFile function. https://www.ghielectronics.com/docs/122/gadgeteer-driver-modification can help you with that. The Microsoft.SPOT.Hardware, Microsoft.SPOT.Graphics, and GHI.Hardware assemblies are required.


using GHI.Utilities;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace BitmapFix
{
	public partial class Program
	{
		void ProgramStarted()
		{
			Mainboard.NativeBitmapConverter = (bmp, buffer, bpp) => Convert(bmp, Bitmaps.BitsPerPixel.BPP16_BGR_BE, buffer);

			this.displayN18.Clear();

			this.displayN18.SimpleGraphics.AutoRedraw = false;
			this.displayN18.SimpleGraphics.DisplayEllipse(Gadgeteer.Color.Red, 1, Gadgeteer.Color.Red, 5, 5, 5, 5);
			this.displayN18.SimpleGraphics.DisplayEllipse(Gadgeteer.Color.Green, 1, Gadgeteer.Color.Green, 15, 5, 5, 5);
			this.displayN18.SimpleGraphics.DisplayEllipse(Gadgeteer.Color.Blue, 1, Gadgeteer.Color.Blue, 25, 5, 5, 5);
			this.displayN18.SimpleGraphics.Redraw();
		}

		public void Convert(Bitmap bitmap, Bitmaps.BitsPerPixel bpp, byte[] outputBuffer)
		{
			var inputBuffer = bitmap.GetBitmap();
			var inputSize = inputBuffer.Length;
			var outputSize = outputBuffer.Length;

			if (outputSize < inputSize / 2) throw new System.ArgumentException("outputBuffer.Length must be half of the bitmap size.", "outputSize");
			if (bpp != Bitmaps.BitsPerPixel.BPP16_RGB_BE && bpp != Bitmaps.BitsPerPixel.BPP16_RGB_LE && bpp != Bitmaps.BitsPerPixel.BPP16_BGR_BE && bpp != Bitmaps.BitsPerPixel.BPP16_BGR_LE) throw new System.NotImplementedException();

			var doSwap = bpp == Bitmaps.BitsPerPixel.BPP16_RGB_BE || bpp == Bitmaps.BitsPerPixel.BPP16_BGR_BE;
			var isBGR = bpp == Bitmaps.BitsPerPixel.BPP16_BGR_BE || bpp == Bitmaps.BitsPerPixel.BPP16_BGR_LE;


			ushort value;
			for (int i = 0, j = 0; i < inputSize; i += 4, j += 2)
			{
				if (isBGR)
					value = (ushort)(((inputBuffer[i] & 0xF8) << 8) | ((inputBuffer[i + 1] & 0xFC) << 3) | (inputBuffer[i + 2] >> 3));
				else
					value = (ushort)(((inputBuffer[i + 2] & 0xF8) << 8) | ((inputBuffer[i + 1] & 0xFC) << 3) | (inputBuffer[i] >> 3));

				if (doSwap)
					value = (ushort)(((value & 0xFF00) >> 8) | ((value & 0x00FF) << 8));

				Utility.InsertValueIntoArray(outputBuffer, j, 2, value);
			}
		}

		public void ConvertToFile(Bitmap bitmap, byte[] outputBuffer)
		{
			var inputBuffer = bitmap.GetBitmap();
			var width = (uint)bitmap.Width;
			var height = (uint)bitmap.Height;

			if (outputBuffer.Length != width * height * 3 + 54) throw new System.ArgumentException("outputBuffer.Length must be width * height * 3 + 54.", "outputSize");

			System.Array.Clear(outputBuffer, 0, outputBuffer.Length);

			Utility.InsertValueIntoArray(outputBuffer, 0, 2, 19778);
			Utility.InsertValueIntoArray(outputBuffer, 2, 4, width * height * 3 + 54);
			Utility.InsertValueIntoArray(outputBuffer, 10, 4, 54);
			Utility.InsertValueIntoArray(outputBuffer, 14, 4, 40);
			Utility.InsertValueIntoArray(outputBuffer, 18, 4, width);
			Utility.InsertValueIntoArray(outputBuffer, 22, 4, (uint)(-height));
			Utility.InsertValueIntoArray(outputBuffer, 26, 2, 1);
			Utility.InsertValueIntoArray(outputBuffer, 28, 2, 24);

			for (int i = 0, j = 54; i < width * height * 4; i += 4, j += 3)
			{
				outputBuffer[j + 0] = inputBuffer[i + 2];
				outputBuffer[j + 1] = inputBuffer[i + 1];
				outputBuffer[j + 2] = inputBuffer[i + 0];
			}
		}
	}
}

4 Likes

@ John - Thank you for the temporary solution !

Likewise @ John - Thank you for the temporary solution.

Hi @ John,
I include camera_43 like explain . https://www.ghielectronics.com/docs/122/gadgeteer-driver-modification.
In build phase, I obtain error : Error 3 Source file ‘…..........\Kits\GHIElectronics\GHI .NET Gadgeteer SDK\Software\GHI .NET Gadgeteer SDK\AssemblyInfoGlobal43.cs’ could not be found C:\Users\sebillen\Documents\Embedded.net micro framework\Tests\Modules\Camera_43\CSC Camera_43
If I copy AssemblyInfoGlobal43.cs’ from original source to Camera_43 project, Builds are correct, but during deployment I have error :
Loading start at a0e00000, end a0e2f494

Assembly: mscorlib (4.3.1.0) Assembly: Microsoft.SPOT.Native (4.3.1.0) Assembly: Microsoft.SPOT.Security.PKCS11 (4.3
.1.0) Assembly: System.Security (4.3.1.0) Assembly: Microsoft.SPOT.Hardware (4.3.1.0)
Assembly: Microsoft.SPOT.Graphics (4.3.1.0) Assembly: Microsoft.SPOT.TinyCore (4.3.1.0)
Assembly: Microsoft.SPOT.IO (4.3.1.0) Assembly: System.IO (4.3.1.0) Assembly: Microsoft.SPOT.Hardware.Usb (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware.SerialPort (4.3.1.0) Assembly: Microsoft.SPOT.Touch (4.3.1.0)
Assembly: Microsoft.SPOT.Ink (4.3.1.0) Assembly: Microsoft.SPOT.Hardware.PWM (4.3.1.0)
Loading Deployment Assemblies.

Attaching deployed file.
Assembly: Gadgeteer (2.43.1.0) Attaching deployed file.
Assembly: GTM.GHIElectronics.DisplayTE35 (4.3.6.0) Attaching deployed file.
Assembly: GHI.Hardware (4.3.6.0) Attaching deployed file.
Assembly: GTM.GHIElectronics.Camera (0.0.0.0) Attaching deployed file.
Assembly: CameraStreaming (1.0.0.0) Attaching deployed file.
Assembly: GTM.GHIElectronics.Button (4.3.6.0) Attaching deployed file.
Assembly: GHI.Usb (4.3.6.0) Attaching deployed file.
Assembly: GTM.GHIElectronics.USBClientDP (4.3.6.0) Attaching deployed file.
Assembly: Microsoft.SPOT.Net (4.3.1.0) Attaching deployed file.
Assembly: GHIElectronics.Gadgeteer.FEZSpider (4.3.6.0) Resolving.

Link failure: some assembly references cannot be resolved!!

Assembly: GTM.GHIElectronics.Camera (0.0.0.0) needs assembly ‘GHI.Premium.USBHost’ (4.2.11.1)
Assembly: GTM.GHIElectronics.Camera (0.0.0.0) needs assembly ‘GHI.Premium.System’ (4.2.11.1)

Assembly: GTM.GHIElectronics.Camera (0.0.0.0) needs assembly ‘Microsoft.SPOT.Graphics’ (4.2.0.0)

Assembly: CameraStreaming (1.0.0.0) needs assembly ‘GTM.GHIElectronics.Camera’ (0.0.0.0)

Error: a3000000

Waiting for debug commands…

Any help please

Forget my post, I found solution.

@ John - has there been any update on fixing this problem? The workaround is pretty awful from a performance perspective.

@ jeffvan - It has been fixed for the next SDK release.

Nice! Any ETA?

For what it’s worth… and I could be wrong, but I was having problems with the workaround generating valid bitmaps until I generated an image whose width was a multiple of 4. I’m no expert here, but I think each row of the pixel data needs to be padded so that it’s a multiple of 4.

“The pixel format is defined by the DIB Header or Extra bit masks. Each row in the Pixel Array is padded to a multiple of 4 bytes in size”

@ jeffvan - The workaround I posted in C# was a quick write up to try and get people going. It is possible some cases are handled incorrectly. We do not have an ETA for the SDK sadly. Since we are moving to a once or twice a year release model, we are trying to get as many fixes into this SDK as we can.

This is disappointing, we use Gadegteer spider kits on university open days to give applicants some hands-on programming that centres around building camera projects. This has completely broken our tasks, spent over 4 grand on the kits too. Is there any way the updated sdk will be updated in the next few weeks? - if not is there anyway I can downgrade the firmware on all our boards and use with an older sdk?

thanks

[quote=“Deeko”]is there anyway I can downgrade the firmware on all our boards and use with an older sdk?
[/quote]

Older SDKs can be found here:

https://www.ghielectronics.com/support/netmf/sdks

Do any of those older SDKs work with VS2013? We have just ghosted over 150 of our lab machines with VS2013 only. I tried installing R4 but installation stopped saying it only works with VS2012.

Previously I installed the latest VS2013 compatible sdk’s/frameworks from codeplex and then installed R5 - everything worked until I tried to use the camera, then the issues highlighted in this thread appeared. I uninstalled R5 then tried to install R4 but fails as above.

cheers
Derek

support for VS2013 is still only “beta” from the netmf team, and there’s no support from GHI. What problem would you like to solve, because you’ll have to pick :slight_smile:

I’d suggest you go back to VS2012 parallel install and you can use R4 or R5 or whatever you need.

Thanks for the replies folks. A VS2012 parallel install not an option at this point as it requires we install it on over 150 machines, we only ever put the newest versions of software on lab images (which forces staff to keep up to date). Its a shame the camera bug is present as everything would have been fine. At least I have a definitive answer and can go ahead and use another platform.

Cheers
Derek

@ Deeko - You should be able to us VS2013 with our 2014 R4, though it is not officially supported by us just yet.

Try the following steps:
-Uninstall any GHI SDK you may have.
-Make sure you have the latest NETMF and Gadgeteer SDKs found at http://netmf.codeplex.com/ and http://gadgeteer.codeplex.com/ (v4.3 SDK R2 Beta and 2.43.1000 respectively).
-Run the 2014 R4 installer. Under Advanced on the first page, deselect Micro Framework and Gadgeteer.

That should let you proceed with our installer.