Image is shown as black and red colors only in ARKit - swift3

We are trying to create a SCNNode with a SCNMaterial which has an image (.png extension) in ARSCNView with the ARKit framework.
The problem is that image rendering has a problem that image is shown as black and red colors only, it doesn't render image correctly.
The problem exists only in iOS 11.2 version. There is no problem in iOS 11.0, 11.1 and 11.3 beta versions.
Our code is below;
let materialMain_Front_Back = SCNMaterial()
let fromBackImage = createImage(color:mainNode_Color)
materialMain_Front_Back.diffuse.contents = UIImage(named: "nodeBackground")
let materialMain_Other = SCNMaterial()
materialMain_Other.diffuse.contents = createImage(color:mainNode_Color)
let boxGeometryMain = SCNBox(width: CGFloat(mainNode_Width), height: CGFloat(mainNode_Height), length: 0, chamferRadius: 0.0)
boxGeometryMain.firstMaterial?.diffuse.contents = UIColor.white
boxGeometryMain.materials = [materialMain_Front_Back, materialMain_Other, materialMain_Front_Back, materialMain_Other, materialMain_Other, materialMain_Other]
let nodeMain = SCNNode(geometry: boxGeometryMain)
nodeMain.position = SCNVector3(x: 0, y: 0, z: -1)
//... other codes
annotationNode.addChildNode(nodeMain)
Does anyone have an idea?

For me, the problem only occured on device, and continues to happen on iOS 11.4.
The solution for me wasn't the image type. In my case I already had JPG textures, however the color space was greyscale.
Xcode showed this as:
Changing it to RGB fixed the problem. After changing it, Xcode shows this:
Oh, and to change from greyscale to RGB using Photoshop, it's as simple as opening the image, and selecting: Image->Mode->RGB Color, as shown here:

I solved it just using .jpg images. Yes just using jpg image instead of png.
I also reported this to Apple as a bug. They answered as that is a problem in 11.2 only with grayscale images with transparency. They fixed it in 11.3.

Related

opencv image rescale wrong offsets

I have the following OpenCV2 code:
cv::Mat old = imread("some.JPG", CV_LOAD_IMAGE_COLOR);
cv::resize(old, old, cv::Size(342,228));
//cv::resize(old, old, cv::Size(342*2,228*2));
Which when displayed in a QT container using
QImage qimg((uchar*)old.data, old.cols, old.rows,QImage::Format_RGB888);
ui->ImgA->setPixmap(QPixmap::fromImage(qimg));
gives me this result (ignore the unrelated slight green tint, that was my screenshot tool being slow...):
When I switch to the commented out resize (aka 4x the size), I get a beautiful sunset photo with proper colors. It also works fine if I switch width and height. Is there something I'm missing in my code that's causing this to have the wrong offset at certain resized sizes? (note the original JPG is 5472 pixels by 3648 pixels)
Try this:
QImage qimg((uchar*)old.data, old.cols, old.rows,old.step,QImage::Format_RGB888);
I posted it as a comment, but now I test it on my computer and without step I get same wrong picture, so I'm sure that it is solution of your problem.

texturepacker rounded border

I created a rounded rectangle on illustrator and export in to png , then added this image to texturepacker and import to cocos2d here is my rectangle,
Have you any idea why there are white pixels on the corner.
Here is image https://dl.dropboxusercontent.com/u/9018754/Screen%20Shot%202014-07-31%20at%2023.28.52.png
Might be that the image was written as png8 with blending towards a white background in Illustrator.
Can you also post the png you created from Illustrator?
-- update --
The image looks fine. I think we can rule out problems with exporting the image.
In your settings "Premultiply Alpha" is off. When importing the image into cocos2d, did you enabled premultipled alpha?
Both values must be matching. Otherwise you will get some strange behaviour.
If it's on in TexturePacker and off in cocos2d you get black outlines.
If it's off in TexturePacker and on in cocos2d you get white outlines.
So: Try enabling it in TexturePacker.
Yes Premultiply Alpha solved my problem
Changing ccConfig.h to
#ifndef CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
#define CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL 1
#endif
and setting premultiply alpha + exclude 1 solved my problem ,
It is written in the comment line
**
` If enabled, the texture coordinates will be calculated by using this formula:
- texCoord.left = (rect.origin.x*2+1) / (texture.wide*2);
- texCoord.right = texCoord.left + (rect.size.width*2-2)/(texture.wide*2);
The same for bottom and top.
This formula prevents artifacts by using 99% of the texture.
The "correct" way to prevent artifacts is by using the spritesheet-artifact-fixer.py or a similar tool.
Affected nodes:
- CCSprite / CCSpriteBatchNode and subclasses: CCLabelBMFont, CCTMXLayer
- CCLabelAtlas
- CCParticleSystemQuad
- CCTileMap
To enabled set it to 1. Disabled by default.
**
I couldnt figure out what is going on at the moment but I will check code deeper ,
Thank you Andreas Löw

CvCvtColor(srcImage,destImage,CV_BGR2Lab) is not working

I am trying to convert an image from RGB Color space to Lab Color Space in opencv. Hence I used CvCvtColor(srcImage,destImage,CV_BGR2Lab), but the destination image destImage is still in RGB color space it does not get converted to Lab color space..To my knowledge everything is fine than why is this failing.
Thanks
The code is here:
IplImage * img = cvCreateImage(cvGetSize(iOriginal), iOriginal->depth,iOriginal->nChannels);
cvCvtColor(iOriginal,img,CV_BGR2Lab);
A user named Neon22 reported a problem with CV_BGR2Lab some time ago. Not sure it has been fixed since then.

Opencv - Overlay image without cvAddWeighted

there are plenty of tutorials showing how to blend two images in opencv:
http://opencv.itseez.com/doc/tutorials/core/adding_images/adding_images.html
http://aishack.in/tutorials/transparent-image-overlays-in-opencv/
But all of them are based on this equation:
opencv blending http://opencv.itseez.com/_images/math/afeb868ed1632ace1fe886b5bfbb6fd933b742b8.png
which means that I will be combining two images by averaging them and consequently I'll be loosing intensity on both images.
For instance, let alpha = 0.5, f0(x) = 255, and f1(x) = 0. After applying this equation, the result image g(x) = 127. That is not what I need. The first image should remain unchanged. And the transparency must be applied in the second one.
My problem is:
the first image f0(x) should not be changed and an alpha should be applied to the second image f1(x) when it overlays the first image f0(x).
I cannot figure out how to do this. Any help?
Unfortunately, alpha channels are not supported by OpenCV. From the imread documentation:
Note that in the current implementation the alpha channel, if any, is stripped from the output image. For example, a 4-channel RGBA image is loaded as RGB if flags > 0.
See this SO post for a possible work around using imagemagick.
Hope that is helpful!

transparent colour being shown some of the time

I am using a LPDIRECT3DTEXTURE9 to hold my image.
This is the function used to display my picture.
int drawcharacter(SPRITE& person, LPDIRECT3DTEXTURE9& image)
{
position.x = (float)person.x;
position.y = (float)person.y;
sprite_handler->Draw(
image,
&srcRect,
NULL,
&position,
D3DCOLOR_XRGB(255,255,255));
return 0;
}
According to the book I have the RGB colour shown as the last parameter will not be displayed on screen, this is how you create transparency.
This works for the most part but leaves a pink line around my image and the edge of the picture. After trial and error I have found that if I go back into photoshop I can eliminate the pink box by drawing over it with the pink colour. This can be see with the ships on the left.
I am starting to think that photoshop is blending the edges of the image so that background is not all the same shade of pink though I have no proof.
Can anyone help fix this by programming or is the error in the image?
If anyone is good at photoshop can they tell me how to fix the image, I use png mostly but am willing to change if necessary.
edit: texture creation code as requested
character_image = LoadTexture("character.bmp", D3DCOLOR_XRGB(255,0,255));
if (character_image == NULL)
return 0;
You are loading a BMP image, which does not support transparency natively - the last parameter D3DCOLOR_XRGB(255,0,255) is being used to add transparency to an image which doesn't have any. The problem is that the color must match exactly, if it is off even by only one it will not be converted to transparent and you will see the near-magenta showing through.
Save your images as 24-bit PNG with transparency, and if you load them correctly there will be no problems. Also don't add the magenta background before you save them.
As you already use PNG, you can just store the alpha value there directly from Photoshop. PNG supports transparency out of the box, and it can give better appearance than what you get with transparent colour.
It's described in http://www.toymaker.info/Games/html/textures.html (for example).
Photoshop is anti-aliasing the edge of the image. If it determines that 30% of a pixel is inside the image and 70% is outside, it sets the alpha value for that pixel to 70%. This gives a much smoother result than using a pixel-based transparency mask. You seem to be throwing these alpha values away, is that right? The pink presumably comes from the way that Photoshop displays partially transparent pixels.