Wolfenstein 3D - Part 9: Detecting enemies
Detecting enemies was much harder than detecting doors. The enemies wear tan-colored images. Unfortunately this hue is similar to the player’s hand and also some of the walls are brown.
Additionally when the enemy is shooting at you, a red overlay flashes on the screen. This makes detecting based on color difficult. One solution is to reverse the red overlay, which is definitely possible. But in the long run, it may be better to detect based on shaped. Color is not the best way to detect objects due to lighting.
The enemy sprite got labelled as many different parts instead of one object. To deal with this issue, OpenCV dilate was used to fill the holes in the binary image a bit. Dilate is actually run twice here.
Another downside of this solution is the amount of computation needed. This is not good when the enemy is shooting at you.
Fig. 1 - One of the test images for detecting enemies
Fig. 2 - Threshold of Fig. 1 using hue range
Fig. 3 - Objects in thresholded images labelled
Fig. 4 - Improved object labelling by applying OpenCV dilate beforehand
Fig. 5 - COM objects labelled in Fig. 3
Fig. 6 - Example of enemy detection actually working
Fig. 7 - Example of enemy detection getting tricked by brown walls
Fig. 8 - Red overlay makes it so enemy is not detected