def test_drawresult(self): self.image_with_person = ImageFile('./images/person.jpg') yoloc = YoloClassifier() yoloResult = yoloc.findEntitiesInPicture(self.image_with_person) img = self.image_with_person.getImage() newImg = yoloc.draw_result(img, yoloResult) self.assertTrue(newImg.shape[0] == 424) self.assertTrue(newImg.shape[1] == 640) self.assertTrue(newImg.shape[2] == 3)
class Testr(unittest.TestCase): def test_findPersonInPicture_with_PersonEasy(self): self.image_with_person = ImageFile('image_with_person2.jpg', './images/image_with_person2.jpg') self.assertTrue(YoloClassifier().findPersonInPicture( self.image_with_person)) def test_findPersonInPicture_without_Person(self): self.image_without_person = ImageFile( './images/image_without_person.jpg') self.assertFalse(YoloClassifier().findPersonInPicture( self.image_without_person)) def test_findPersonInPicture_with_PersonDifficult(self): self.image_with_person = ImageFile( 'image_with_person_difficult.jpg', './images/image_with_person_difficult.jpg') self.assertTrue(YoloClassifier().findPersonInPicture( self.image_with_person)) def test_findPersonInPicture_with_PersonEasy2(self): self.image_with_person = ImageFile('./images/image_with_person9.jpg') self.assertTrue(YoloClassifier().findPersonInPicture( self.image_with_person)) def test_getParentDir(self): cwd = os.getcwd() if (cwd.endswith('/tests')): parDir = os.path.abspath(os.path.join(cwd, "..")) weights_file = os.path.join(parDir, 'yolo/YOLO_small.ckpt') else: weights_file = os.path.join(cwd, 'yolo/YOLO_small.ckpt') self.assertTrue(os.path.isfile(os.path.isfile(weights_file))) def test_drawresult(self): self.image_with_person = ImageFile('./images/person.jpg') yoloc = YoloClassifier() yoloResult = yoloc.findEntitiesInPicture(self.image_with_person) img = self.image_with_person.getImage() newImg = yoloc.draw_result(img, yoloResult) self.assertTrue(newImg.shape[0] == 424) self.assertTrue(newImg.shape[1] == 640) self.assertTrue(newImg.shape[2] == 3) def test_findEntitiesInPicture(self): self.image_with_person = ImageFile('./images/person.jpg') res = YoloClassifier().findEntitiesInPicture(self.image_with_person) self.assertTrue(res[0][0], 'person') # def test_findPersonInPictureWithCandidates(self): self.image_with_person = ImageFile('./images/image_with_person.jpg') res = YoloClassifier().findPersonInPictureWithCandidates( self.image_with_person) self.assertTrue(res)
def findPersonInPictureWithCandidates(self, theImage): candidates = theImage.createYoloCandidates() i = 0 for oneCandidate in candidates: logging.info( "YoloClassifier: Searching for person in picture %s candidate %s", theImage.getFilename(), str(i)) filename = 'candidate_' + str(i) + '.jpg' cv2.imwrite(filename, oneCandidate) theImageCandidate = ImageFile(filename) yoloResult = self._detect_from_cvmat( theImageCandidate.getMatplotlibImage()) logging.info('YoloClassifier: Number of entities found %s', str(len(yoloResult))) logging.info('YoloClassifier: Detected entities %s', self._getDetectedEntities(yoloResult)) for item in yoloResult: if item[0] == "person": # cv2.imwrite('goodcandidate' + str(i) + '.jpg',oneCandidate) return (True) i = i + 1 return False
def main(): logging.info('************* BEGIN check_false_alarms.py ************') mailManager = EmailManager() #Count number of emails numMails = mailManager.checkMailbox(MailboxSettings()) logging.info('Found %s emails', str(numMails)) if (numMails > 0): yolo = YoloClassifier() #For every email if (numMails > 5): numMails = 5 logging.info('Only 5 emails will be checked in this execution.') for i in range(numMails): #Get the pictures logging.info('**** Checking email with ID %i ****', i) eMailInfo = mailManager.getInfoFromEmail(i, MailboxSettings()) images = eMailInfo.getAttachments() if (len(images) == 0): logging.info('No images found in the email with ID %i', i + 1) else: #For every image, call Yolo try to detect a person for oneImage in images: logging.info('Checking image %s', oneImage) if (yolo.findPersonInPictureWithCandidates( ImageFile(oneImage)) == True): logging.info('Found person in picture %s', oneImage) #Send email to notify there is a real alert #Prepare the contents of the alert eMailContentAlert = mailManager.prepareAlert(eMailInfo) #Send the email mailManager.sendEmail(eMailContentAlert, SmtpSettings()) break else: logging.info('No person found in picture %s', oneImage) #Remove the emails once they have been processed #mailManager.multipleDeleteEmail(range(numMails),MailboxSettings()) logging.info('************* END check_false_alarms.py ************')
def test_createYoloCandidates(self): self.image_with_person = ImageFile('./images/image_with_person.jpg') res = self.image_with_person.createYoloCandidates() self.assertTrue(len(res) > 0)
def make_image(self, filename): self.image = ImageFile(filename, self.identifier, self.application) return self.image
def test_findPersonInPictureWithCandidates(self): self.image_with_person = ImageFile('./images/image_with_person.jpg') res = YoloClassifier().findPersonInPictureWithCandidates( self.image_with_person) self.assertTrue(res)
def test_findEntitiesInPicture(self): self.image_with_person = ImageFile('./images/person.jpg') res = YoloClassifier().findEntitiesInPicture(self.image_with_person) self.assertTrue(res[0][0], 'person')
def test_findPersonInPicture_with_PersonEasy2(self): self.image_with_person = ImageFile('./images/image_with_person9.jpg') self.assertTrue(YoloClassifier().findPersonInPicture( self.image_with_person))
def test_findPersonInPicture_with_PersonDifficult(self): self.image_with_person = ImageFile( 'image_with_person_difficult.jpg', './images/image_with_person_difficult.jpg') self.assertTrue(YoloClassifier().findPersonInPicture( self.image_with_person))
def test_findPersonInPicture_without_Person(self): self.image_without_person = ImageFile( './images/image_without_person.jpg') self.assertFalse(YoloClassifier().findPersonInPicture( self.image_without_person))