# Sprite Detection
A [sprite](<https://en.wikipedia.org/wiki/Sprite_(computer_graphics)>) is a small [raster graphic](https://en.wikipedia.org/wiki/Raster_graphics) (a bitmap) that represents an object such as a [character, a vehicle, a projectile, etc.](https://www.youtube.com/watch?v=a1yBP5t-fSA)
![Metal Slug ](metal_slug_sprite_large.png)
Sprites are a popular way to create large, complex scenes as you can manipulate each sprite separately from the rest of the scene. This allows for greater control over how the scene is rendered, as well as over how the players can interact with the scene.
Sprites are mainly used in 2D video games, such as [Shoot’em up](https://en.wikipedia.org/wiki/Shoot_%27em_up) in which the hero combats a large number of enemies by shooting at them while dodging their fire:
## Sprite Animation
Several sprites, representing a same object, can be rendered in quick succession to give the illusion of movement of this object (animation).
For example, the animation of the hero Marco Rossi (Metal Slug), running with a gun, is composed of 9 sprites:
![Metal Slug Sprite Running with a Gun](metal_slug_sprites_running_with_gun.png)
## Sprite Sheet
It is not uncommon for games to have tens to hundreds of sprites. Loading each of these as an individual image would consume a lot of memory and processing power. To help manage sprites and avoid using so many images, many games use [sprite sheets](https://www.youtube.com/watch?v=crrFUYabm6E) (also known as image sprites).
A sprite sheet consists of multiple sprites in one image. In other words, sprite sheets pack multiple sprites into a single picture. Using sprite sheet, video game developers create sprite sheet animation representing one or several animation sequences while only loading a single file:
![Metal Slug Sprites](metal_slug_sprite_sheet_large.png)
## Sprite Bounding Box
A frame (bounding box) can be used to delimit the sprite in the sprite sheet. This bounding box is defined with two 2D points top_left and the bottom_right, which their respective coordinates x and y are relative to the top-left corner of the sprite sheet’s image.
![Shape Bounding Boxes](metal_slug_sprite_detection_bounding_boxes.png)
## Sprite Mask
The mask of a sprite defines the 2D shape of the sprite. For example, the sprite sheet [metal_slug_sprite_standing_stance.png](metal_slug_sprite_standing_stance_large.png) contains the 3 following sprites:
![Metal Slug Standing Stance](metal_slug_sprite_standing_stance_large.png)
The masks of these sprites are respectively:
## Optimized Sprite Sheet
Sprites could be evenly placed in the sprite sheet according to their bounding box. The disadvantage is that this method of placement wastes a lot of memory because of all the additional transparency of each sprite, especially when sprites have different width and height.
The developers are aware of the wasted memory and started to optimize the space in the sprite sheets. Sprites are placed close to each others, depending on their shape. The bounding box of a sprite may intersect the bounding box of another sprite, but the shape of this sprite is always separated from the shape of any other sprites with at least 1 transparent pixel.
![Optimized Sprite Sheet](optimized_sprite_sheet.png)
This space optimization is even more efficient when some big sprites have concave shape (i.e., shape that curves inward):
# Aim of the project
- Detect sprites in the input image and draw those sprites to new image with its bounding box and mark.
# Usage Information
- Python 3.6
`bash $ pipenv install spritesheet-lecuong91 `
`python image = SpriteSheet('metal_slug_sprites_running_with_gun.png') sprites, label = image.find_sprites() sprite_label_image = image.create_sprite_labels_image() sprite_label_image.save('test.png') `
# Contact Information If you have any problems using this library, please use the contact below.
This project is licensed under the MIT License - see the LICENSE.txt file for details
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size spritesheet_lecuong91-0.0.2-py3-none-any.whl (8.9 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size spritesheet_lecuong91-0.0.2.tar.gz (5.7 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for spritesheet_lecuong91-0.0.2-py3-none-any.whl
Hashes for spritesheet_lecuong91-0.0.2.tar.gz