Exemple #1
0
def exp_mei():
    for i in range(20):
        file = get_video_filename("walking", i + 1, np.random.randint(1, 5))
        ac = acmhi.ActivityQuantifier("walking", filename=file)
        mei, _ = ac.build_mei_mhi()
        mei_image = np.int32(mei * 255.)
        cv2.imwrite(
            "output/mei_image_{}_person{}_d{}.png".format(
                ac.action, ac.person_num, ac.d_num), mei_image)
Exemple #2
0
 def test_hu_moments(self):
     for _ in range(100):
         ac = acmhi.ActivityQuantifier(np.random.choice(ACTIONS))
         meis, mhis = ac.build_mei_mhi()
         for mhi in mhis:
             hus = ac.hu_moments(mhi)
             c_moms = cv2.moments(np.uint8(mhi))
             compare = cv2.HuMoments(c_moms)
             for i, hu in enumerate(hus):
                 self.assertTrue(np.isclose(hu, compare[i][0], rtol=0.01),
                     "{} != {} :: {}".format(hu, compare[i][0], i+1))
Exemple #3
0
    def test_binary_image(self):
        ac = acmhi.ActivityQuantifier("walking", "person01_walking_d1_uncomp.avi")
        video = ac.load_video("walking", "person01_walking_d1_uncomp.avi")
        c = 0
        curr_img = ac.prepare_frame(video.next())
        while c < 25:
            prev_img = curr_img
            curr_img = ac.prepare_frame(video.next())
            c += 1

        result = ac.binary_mei(curr_img, prev_img)
        cv2.imwrite("test_output/binary_img.png", result * 255)
        cv2.imwrite("test_output/binary_img_curr.png", curr_img)
        self.assertTrue(np.any(result), "Binary MEI Image")
Exemple #4
0
 def test_moments(self):
     ac = acmhi.ActivityQuantifier(np.random.choice(ACTIONS))
     meis, mhis = ac.build_mei_mhi()
     for mhi in mhis:
         M_00, M_10, M_01 = ac.img_moments(mhi)
         moments = cv2.moments(np.uint8(mhi))
         self.assertTrue(np.isclose(moments['m00'], M_00, atol=3.),
             "{} != {}".format(moments['m00'], M_00)
         )
         self.assertTrue(np.isclose(moments['m10'], M_10, atol=3.),
             "{} != {}".format(moments['m10'], M_10)
         )
         self.assertTrue(np.isclose(moments['m01'], M_01, atol=3.),
             "{} != {}".format(moments['m01'], M_01)
         )
Exemple #5
0
def exp_mei_mhi(act="handclapping"):
    for i in range(5):
        print "Running mei and mhi images for " + act
        file = get_video_filename(act, i + 1, 3)  #np.random.randint(1,5))
        ac = acmhi.ActivityQuantifier(act, filename=file)
        meis, mhis = ac.build_mei_mhi()
        for i, mhi in enumerate(mhis):
            mhi_image = np.int32(np.around((np.float32(mhi) / ac.tau) * 255.))
            mei_image = np.int32(meis[i] * 255.)
            cv2.imwrite(
                "output/mhi_image_{}_person{}_d{}_{}.png".format(
                    ac.action, ac.person_num, ac.d_num, i), mhi_image)
            cv2.imwrite(
                "output/mei_image_{}_person{}_d{}_{}.png".format(
                    ac.action, ac.person_num, ac.d_num, i), mei_image)
Exemple #6
0
 def test_central_moments(self):
     ac = acmhi.ActivityQuantifier(np.random.choice(ACTIONS))
     meis, mhis = ac.build_mei_mhi()
     for mhi in mhis:
         mus, vs = ac.central_moments(mhi)
         c_moms = cv2.moments(np.uint8(mhi))
         self.assertTrue(np.isclose(mus['20'], c_moms['mu20'], rtol=0.01),
                         "{} != {}".format(mus['20'], c_moms['mu20']))
         self.assertTrue(np.isclose(mus['11'], c_moms['mu11'], rtol=0.01),
                         "{} != {}".format(mus['11'], c_moms['mu11']))
         self.assertTrue(np.isclose(mus['12'], c_moms['mu12'], rtol=0.01),
                         "{} != {}".format(mus['12'], c_moms['mu12']))
         self.assertTrue(np.isclose(mus['02'], c_moms['mu02'], rtol=0.1),
                         "{} != {}".format(mus['02'], c_moms['nu02']))
         self.assertTrue(np.isclose(mus['03'], c_moms['mu03'], rtol=0.1),
                         "{} != {}".format(mus['03'], c_moms['nu03']))
         self.assertTrue(np.isclose(mus['21'], c_moms['mu21'], rtol=0.1),
                         "{} != {}".format(mus['21'], c_moms['mu21']))
         self.assertTrue(np.isclose(mus['30'], c_moms['mu30'], rtol=0.1),
                         "{} != {}".format(mus['30'], c_moms['mu30']))
Exemple #7
0
 def test_mhi(self):
     ac = acmhi.ActivityQuantifier(np.random.choice(ACTIONS))
     _, mhis = ac.build_mei_mhi()
     c = 0
     for mhi in mhis:
         mhi_image = np.int32(np.around((np.float32(mhi) / ac.tau) * 255.))
         cv2.imwrite(
             "test_output/mhi_image_{}_person{}_d{}_{}.png".format(
                 ac.action,
                 ac.person_num,
                 ac.d_num,
                 c
             ),
             mhi_image
         )
         c += 1
         # MEI image should be neither all white or black
         gtz = mhi_image[mhi_image > 0]
         test = gtz[gtz < 255]
         self.assertTrue(np.any(test), "MHI is incorrect, b&w")
Exemple #8
0
    def test_mei(self):
        ac = acmhi.ActivityQuantifier(np.random.choice(ACTIONS))
        meis, _ = ac.build_mei_mhi()
        c = 0
        for mei in meis:
            mei_image = mei * 255
            cv2.imwrite(
                "test_output/mei_image_{}_person{}_d{}_{}.png".format(
                    ac.action,
                    ac.person_num,
                    ac.d_num,
                    c
                ),
                mei_image
            )
            c += 1

            # MEI image should be neither all white or black
            self.assertFalse(np.all(mei_image == 255), "MEI is incorrect, all white")
            self.assertFalse(np.all(mei_image == 0), "MEI is incorrect, all black")