DEV Community

Cover image for (AI for defence) using OpenCv to detect a fighter jet
es404020
es404020

Posted on • Updated on

(AI for defence) using OpenCv to detect a fighter jet

Hi, guys welcome to this new series where i blog about how opencv can be used in build military tools for combat.

In this short tutorial we would look at how to build a simple app to detect fighter jet in the sky .

In other to build a simple fighter detection system .The following test are required

1.Create a statistical model of the background scene using createBackgroundSubtractorKNN().

2.Compare the current frame with the background model to create a foreground mask using the apply() method

3.Apply erosion to the foreground mask to reduce noise using erode()

  1. Find the bounding rectangle that encompasses all the non-zero points in the foreground mask using boundingRect()

`
bg_sub = cv2.createBackgroundSubtractorKNN(history = 200)
while True:
ret, frame = video_cap.read()

if frame is None:
    break
else:
    frame_erode = frame.copy()
Enter fullscreen mode Exit fullscreen mode

fg_mask = bg_sub.apply(frame)
fg_mask_erode = cv2.erode(fg_mask, np.ones(ksize, np.uint8))
motion_area_erode = cv2.findNonZero(fg_mask_erode)
xe, ye, we, he = cv2.boundingRect(motion_area_erode)

`
Note this solution works best when the camera is static.

Full code would not be shown because of how sensitive this topic is .

Thanks for reading

Co author: Ebele Precious Okemba

Top comments (0)