How to differenciate sprite parts in one image - cocos2d-iphone

I have one image of house and in house there are several parts available but in only one image.
I want to paint all parts like red color for wall and black color for roof. But only one image i have so how it is possible to color different portions in one image??
Can i use cocos2d or anything else for this interesting stuff?
Thanks in advance.

You can fill different colors on different part of image by making different CGRect sprite on image to be fill but I am sure that it would not solve your problem as the house image must have different shape to be fill like circular ,triangular or rectangular.And using CGrect will give you filling of rectangular size only.
The best possible solution for this would be using different images as the part of house.There may be other ways also but they would be complex and problematic so try using more than one images as you can fill each image easily.

Related

Averaging of two images with mask

I have two image like this:
I create two mask, which show me position of each image on scene.
I create mask which show me intersection of two images.
I create intersection mask with
cv::bitwise_and(mask_left, mask_right, mask_intersection);
I want adding two images together. Where pixels of mask_intersection is white, I want use average value of pixels on both images. Here is result, where I just add one image on another. The problem is sharp border, which I want to solve with averaging of both images only on mask_intersection.
I don't know how to solve this problem the easiest way.
For averaging the two images where the mask intersect, you could use copyTo.
Supposing you have maskIntersection, image1, image2 and finalImage, the code would look something like:
((image1 + image2) * 0.5).copyTo(finalImage, maskIntersection)
Even though this answers your question of averaging the two images, I don't think it will provide very good results. Blending two images together is usually a more involved process. Take a look at this class to have a quick overview of what is required.
Te process you are loocking for is called blending, and you can achieve it using cv::addWeighted(), then just multiply the result by the mask to cut off zones of the image that you donĀ“t want to blend.

Python: Reduce rectangles on images to their border

I have many grayscale input images which contain several rectangles. Some of them overlap and some go over the border of the image. An example image could look like this:
Now i have to reduce the rectangles to their border. My idea was to make all non-white pixels which are less than N (e.g. 3) pixels away from the border or a white pixel (using the Manhatten distance) white. The output should look like this (sorry for the different-sized borders):
It is not very hard to implement this. Unfortunately the implementation must be fast, because the input may contain extremly many images (e.g. 100'000) and the user has to wait until this step is finished.
I thought about using fromimage and do then everything with numpy, but i did not find a good solution.
Maybe someone has an idea or a hint how this problem may be solved very efficient?
Calculate the distance transform of the image (opencv distanceTrasform http://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html)
In the resulted image zero all the pixels that have value bigger than 3

cocos2d-x ResolutionPolicy::SHOW_ALL show nice images instead of black gaps

When in cocos2d-x you set ResolutionPolicy::SHOW_ALL then it might appear black areas from top-bottom or from left-right sides. Can I cover the black area with some nice images?
I don't think you can just add something into those back areas.
Instead the solution is to build a scene which already contain the nice images you want to add. The steps are:
Use this inside your AppDelegate::applicationDidFinishLaunching() to detect screen size:
CCSize frameSize = pEGLView->getFrameSize();
Set a design resolution proportional to this frameSize maintaining its aspect ratio.
Put your "content" in the mid. Then, you have to calculate where are the "black areas" and add sprites to cover them. Keep in mind that for different screen the holes can be different, so you need to do some maths there and properly cover different hole sizes.
So, doing ResolutionPolicy::SHOW_ALL sets the openGL view to that size. That's why that can't be done with that.
On the other hand, there are many ways to tackle this.
What i did was :
1. Don't set the ResolutionPolicy.
Use a layer for those nice images/effects.
Create a new layer in that same scene and set the width and height of that layer according to aspect ratio of your content. And make this as your primary game view.

Cocos2d - hiding, clipping or masking sprite like in game Candy Crush

I have a problem and I saw it also in the game Candy Crush Saga, where they successfully dealt with it. I would like the sprite to show only when it is in the board (see image link below). The board can be of different shapes, like the levels in the mentioned game.
Has anyone some ideas how can this be achieved with Cocos2d?
I will be very glad if someone has some tips.
Thank you in advance.
image link: http://www.android-games.fr/public/Candy-Crush-Saga/candy-crush-saga-bonus.jpg
In Cocos2d you can render sprites at different z levels. Images at a lower z-level will be drawn first by the graphic card and the images (sprites) with a higher z-value will be drawn later. Hence if an image (say A) is at the same position of the other but has a higher z-value you will see only the pixels of image A where the two images intersect.
Cocos2d uses also layers so you can decide to add Sprites to a layer and set the layer to a specific z value. I expect that they used a layer for the board (say at z=1) with a PNG image containing transparent bits in the area where you can see the sprites, and a second layer at z=0 for the sprites. In this way you can only see the sprites when they are in the transparent area.
Does this help?
I found out Cocos2d has a class CCClippingNode which does exatclly what I wanted. First I thought it can clip only rectangular areas, but after some research I found it can clip also paths.

Creating foreground background array in QT

I'm having a problem with creating an array that gives me the information about 2 images that are drawn upon each other.
What I have is 1 image as background (the sea) and 1 image as foreground (landscape) the landscape is not so big as the sea, so when drawn upon each other you can see the sea as well as the landscape on it.
Now I want to make an array that sets me an 0 if it is the sea and a 1 if it is the landscape. So I could use
this array to do some collision detection later. The problem is I don't find how to make a bytearray from it.
off length * width of the images.
I have both images in an QImage, but I don't find how to create the array with a for loop or something.
Both images are drawn upon each other with the QPainter function.
Can someone help me?
Kind regards,
If you draw the two images upon each other with the QPainter class, you loose any information about them, they are just drawings now. you must create methods and objects to implement your school project. I know that you can't use the QGraphicsView, but what you need is to look how qgraphicsview works so you will have a bit of information on how to implement your own collision system.
1 - you need to keep the Retangle of your drawings ( all of them ) saved somewhere. a QList will do.
2 - you need the Positions of your Drawings too, so y ou know where they are, besides the retangles.
with the positions, and the rectangles, all you need to do is check if one rectangle intersects another.
I did it with 2 forloops and used black and blue to determine the fore and background. So I can only use black and blue.