This study addressed a system design to detect the presence of military personnel (combatants or non-combatants) and civilians in real-time using the convolutional neural network (CNN) and a new loss function called electrostatic loss. The basis of the proposed electrostatic loss is the triplet loss algorithm. Triplet loss’ input is a triplet image consisting of an anchor image (xa), a positive image (xp), and a negative image (xn). In triplet loss, xn will be moved away from xa but not far from both xa and xp. It is possible to create clusters where the intra-class distance becomes large and does not determine the magnitude and direction of xn displacement. As a result, the convergence condition is more difficult to achieve. Meanwhile, in electrostatic loss, some of these problems are solved by approaching the electrostatic force on charged particles as described in Coulomb's law. With the inception ResNet-v2 128-dimensional vectors network within electrostatic loss, the system was able to produce accuracy values of 0.994681, mean average precision (mAP) of 0.994385, R-precision of 0.992908, adjusted mutual information (AMI) of 0.964917, and normalized mutual information (NMI) of 0.965031.