Getting a remote image to use with Codename One - image

I am trying to retrieve a remote image to use it in a label. My code is the following:
Dimension dimension = new Dimension(100, 100);
ImageDownloadService.createImageToStorage("http://www.example.com/logo-icono.ico",label, "cacheID-unique-identifier",dimension);
However, when I run the project, I got this error:
java.lang.IllegalArgumentException: create image failed for the given image data of length: 3906
at com.codename1.ui.Image.createImage(Image.java:627) at com.codename1.ui.Image.createImage(Image.java:627)
at com.codename1.ui.EncodedImage.getInternal(EncodedImage.java:270)
at com.codename1.ui.EncodedImage.getInternalImpl(EncodedImage.java:245)
at com.codename1.ui.EncodedImage.drawImage(EncodedImage.java:433)
at com.codename1.ui.Graphics.drawImage(Graphics.java:505)
at com.codename1.ui.plaf.DefaultLookAndFeel.drawComponent(DefaultLookAndFeel.java:1079)
at com.codename1.ui.plaf.DefaultLookAndFeel.drawLabel(DefaultLookAndFeel.java:380)
at com.codename1.ui.Label.paint(Label.java:335)
at com.codename1.ui.Component.internalPaintImpl(Component.java:1029)
at com.codename1.ui.Component.paintInternalImpl(Component.java:1003)
at com.codename1.ui.Component.paintInternal(Component.java:978)
at com.codename1.ui.Container.paint(Container.java:903)
at com.codename1.ui.Component.internalPaintImpl(Component.java:1023)
at com.codename1.ui.Component.paintInternalImpl(Component.java:1003)
at com.codename1.ui.Component.paintInternal(Component.java:978)
at com.codename1.ui.Container.paint(Container.java:903)
at com.codename1.ui.Form.paint(Form.java:2716)
at com.codename1.ui.Component.internalPaintImpl(Component.java:1023)
at com.codename1.ui.Component.paintInternalImpl(Component.java:1003)
at com.codename1.ui.Component.paintInternal(Component.java:978)
at com.codename1.ui.Component.paintInternal(Component.java:946)
at com.codename1.ui.Component.paintComponent(Component.java:1223)
at com.codename1.ui.Component.paintComponent(Component.java:1175)
at com.codename1.impl.CodenameOneImplementation.paintDirty(CodenameOneImplementation.java:382)
at com.codename1.impl.javase.JavaSEPort.paintDirty(JavaSEPort.java:963)
at com.codename1.ui.Display.edtLoopImpl(Display.java:993)
at com.codename1.ui.Display.mainEDTLoop(Display.java:920)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
at com.codename1.ui.Image.createImage(Image.java:627)
What am i doing wrong?

Ico files are windows specific and most devices don't support loading them. Only PNG & JPEG are guaranteed in devices.
I would also recommend using URLImage where applicable.

Related

Send an image from smart device to the server in Genexus

I know there is already a similar question but the answers to that didn't work for me
I'm working with Genexus 16U11 and I have a panel with an image variable (called &sourceImage) with control type as "SD Image Annotation". I need to send this image to the server, in a specific folder. According the documentation if I call a procedure using the image as variable this should go on the server but it's not working. I can't find the image anywhere, I searched also in the PublicTempStorage directory, in the procedure is as the variable is empty.
I tried also to convert the image in base64 to send it as longvarchar to the procedure
&blob = &sourceImage.GetAnnotatedImage()
&longvarchar = ToBase64(&blob)
but in this way I can only get this string ZmlsZTovLy8vc3RvcmFnZS9lbXVsYXRlZC8wL0FuZHJvaWQvZGF0YS9jb20uYXJ0ZWNoLnJpY2hpZXN0YXBlcm1lc3NpMTZ1MTEuc2Zpcm1hL2ZpbGVzL3RyYW5zZm9ybWF0aW9ucy8yMDIyLTAzLTE4LS0xNC00My0yNi02MTQ2NDcyMTA5MjM5NDU3NzgzODAxLnBuZw==
that is the path of the file
file:////storage/emulated/0/Android/data/com.artech.richiestapermessi16u11.sfirma/files/transformations/2022-03-18--14-43-26-6146472109239457783801.png
I tried with file variable, blob, image, extra images, method fromUrl, nothing is working.
What am I doing wrong?
To upload the image to the server you need to call the procedure in the server (Connectivity=Online).
Then the image variable will be send to the server and you can save, copy, etc. there.
For example, save in a Transaction with a code like this:
Call in the panel:
Composite
&resultImage = &ImageA.GetAnnotatedImage()
procSaveImage(&resultImage)
EndComposite
Procedure online:
&TrnData = new()
&TrnData.TrnDataImage = &parmImage
&TrnData.Insert()
if &TrnData.Success()
commit
Working in Genexus v17u8 .

Yolov4 error when trying to display image on custom model

I have trained my own model, using my own custom dataset, using Yolov4, and I have downloaded the .cfg, .weights and .data files.
When I try to run my model using:
darknet.exe detector test cfg/obj.data cfg/yolov4-og.cfg custom-yolov4-detector_best.weights
I get the error:
Error: l.outputs == params.inputs filters= in the [convolutional]-layer doesn't correspond to classes= or mask= in [yolo]-layer
I don't know if this is an error on my part, with the command I am running, or an error from the model I trained.
Any help would be appreciated.
I am assuming you are using the main darknet repo AlexeyAB. Please make sure you follow the following instructions:
Make sure you assign the correct classes number in the config file.
Change filters=255 to filters=(classes + 5)x3 in the 3
[convolutional] before each [yolo] layer, keep in mind that it only
has to be the last [convolutional] before each of the [yolo] layers
https://github.com/AlexeyAB/darknet/blob/0039fd26786ab5f71d5af725fc18b3f521e7acfd/cfg/yolov3.cfg#L603
https://github.com/AlexeyAB/darknet/blob/0039fd26786ab5f71d5af725fc18b3f521e7acfd/cfg/yolov3.cfg#L689
https://github.com/AlexeyAB/darknet/blob/0039fd26786ab5f71d5af725fc18b3f521e7acfd/cfg/yolov3.cfg#L776
So if classes=1 then should be filters=18. If classes=2 then write filters=21
(Generally filters depends on the classes, coords and number of masks, i.e. filters=(classes + coords + 1)*, where mask is indices of anchors. If mask is absent, then filters=(classes + coords + 1)*num)
Reference: https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects

BackgroundSubtractorMOG2 bgm->apply throws exception in Visual Studio 2017

I'm new to C++ and opencv and having difficulty running the background subtractor model. I'm using Visual Studio 2017 (VC++) and opencv 3.2.
I need to use BackgroundSubtractorMOG2 and it creates the model fine but throws exception when I pass it a new frame that is converted from an encoded image (because I'm using a USB3 camera that doesn't allow direct reading of frame by opencv) to cv::Mat. The code snippet is below
if (EncodeRawImage(pRawImage, &frameDesc, imageFormat, &pEncodedImage, &encodedImageSize) == SUCCESS) {
// Convert current raw image to openCV Mat format for analysis
auto store = gcnew cli::array<Byte>(encodedImageSize);
System::Runtime::InteropServices::Marshal::Copy(IntPtr(pEncodedImage), store, 0, encodedImageSize);
auto stream = gcnew System::IO::MemoryStream(store);
System::Drawing::Bitmap^ bitmapFrame = safe_cast<System::Drawing::Bitmap ^> (Image::FromStream(stream));
Mat imgBuf = Mat(bitmapFrame->Width, bitmapFrame->Height, CV_8U, pEncodedImage);
Mat imgMat = imdecode(imgBuf, CV_LOAD_IMAGE_COLOR);
bgm->apply(imgMat , fgMaskMOG);
returnCode = 1;
}
The exception is
owner 0x0000023afa2a2ec0 Information not available, no symbols loaded for opencv_world320d.dll> cv::detail::PtrOwner *
stored 0x0000023afa29baa0 Information not available, no symbols loaded for opencv_world320d.dll> cv::BackgroundSubtractorMOG2 *
Even though the opencv320d.lib are linked properly and a few other basic opencv samples run for me in the same program (e.g., cv::subtract, cv::calcHist etc). I wonder if it because the image size is too large (4608x3288) and bitmpaFrame that I'm creating may have an issue?
Or if I'm trying to access image data in the stream/memory in a way that is not allowed?
Even though the Information not found string is still there when I do the breakpoint, I just found that the model was throwing exception because of large image size as I mentioned in my original question (4608x3288). I resizes the image (resize(newImageMat, newImageMat, cv::Size(1000, 1000 * newImageMat.rows / newImageMat.cols), INTER_LINEAR);) and the error is gone and the model learns and shows the result. The text maybe a Visual Studio bug since I was reading about a similar issue here https://stackoverflow.com/a/7736034/3377101?

How to create a Mat from byte[] with JavaCV

Trying to use JavaCV for image processing to rotate image according to it's Exif data.
Reading and writing from file to either Mat or IplImage works, but since the file is being upload or downloaded, I also want to be able to do the same thing processing byte[] instead of having to write to file.
However, I cannot find how to create a Mat instance from byte[].
The method 'aMat.put(0, 0, byteArray)' which is mentions in some answers is not available on a Mat instance in javacp version 1.0 using javacpp-presets:opencv:3.0.0.
Trying to put the bytes in the Mat data via : 'aMat.data().put(imageBytes, 0, 0)' throws a NPE because data() returns null. I cannot find how to set the data since it is a JNI call.
Any idea's on how to create a opencv_core.Mat from byte[]?
Did you try using:
yourMat.data().put(yourByteArray);
Just make sure yourMat is of the right size.

A null reference or invalid value was found [GDI+ status: InvalidParameter]

I am running an MVC3 app on Mono/linux and everything is working fine with the exception of an image upload utility. Whenever an image upload is attempted i get the Invalid Parameter error from within the method below:
System.Drawing.GDIPlus.CheckStatus(status As Status) (unknown file): N 00339
System.Drawing.Bitmap.SetResolution(xDpi As Single, yDpi As Single)
I've googled this error extensively and have found that the Invalid parameter error can often be misleading, and could fire if for example there was an error with the upload itself, or if the image was not fully read. This runs fine on IIS/Windows, but I've not been able to get it to work in Mono.
Apache2
Mono 2.10.8.1
Am i missing something simple or do i need to find a different way to handle image manipulation for mono?
After doing quite a bit of testing, I was able to determine the root of my error. I was attempting to use the Image.HorizontalResolution and Image.VerticalResolution properties for Bitmap.Resolution . While these properties were set on the initial upload (where the file is read into a stream from the tmp directory), when i posted back with the base64 encoded string of the image itself, it appears these values were lost somehow. Because of this the SetResolution method failed.
For whatever reason i do not have this issue on IIS/Windows, the properties exist in both circumstances.
I encountered a similar issue. A Bitmap loaded from disk, reported bmp.HorizontalResolution==0 and bmp.VerticalResolution==0 when they were both==300. This behaviour does not occur on Windows.
A bit more digging, I found that the following test fails:
[Test]
public void GDI_SetResoltion()
{
var b1 = new Bitmap (100, 100);
Assert.That (b1.HorizontalResolution, Is.Not.EqualTo (0));
Assert.That (b1.VerticalResolution, Is.Not.EqualTo (0));
}
I believe Windows will default resolution to 96 dpi.

Resources