def test_WithBoundingBox(self):
        bbox = RegionOfInterest(30, 40, 210, 302)
        species_id = SingleSpeciesId(
            bbox,
            [SpeciesScore(3, 0.4), SpeciesScore(2, 0.3)])

        SpeciesSelectionModule.speciesIdCallback(
            SpeciesIDResponse(3, [species_id]), self.module)

        self.checkSignalUpdate(3)

        d = self.module.GetOutputDict()
        self.assertEquals(d['state'], State.CANDIDATES_ARRIVED)
        self.assertEquals(d['name'], 'SpeciesSelection')
        foundBbox = d['bbox']
        self.assertEquals(foundBbox['x_offset'], 30)
        self.assertEquals(foundBbox['y_offset'], 40)
        self.assertEquals(foundBbox['height'], 210)
        self.assertEquals(foundBbox['width'], 302)
        self.assertEquals(len(d['species_hits']), 3)
        self.checkSpeciesInfo(self.speciesInfo[3], d['species_hits'][0])
        self.checkSpeciesInfo(self.speciesInfo[2], d['species_hits'][1])
        self.checkSpeciesInfo(SpeciesSelectionModule.UNKNOWN_SPECIES,
                              d['species_hits'][2])
        self.assertEquals(d['user_chose'], False)
        self.assertEquals(d['idx'], 0)
Example #2
0
def RequestCallback(requestMsg, selector, publisher, nSpecies):
    '''Callback for a SpeciesIDRequest that chooses a random set of species.

    Inputs:
    selector - RandomSpeciesSelector to handle the random picks
    publisher - object to publish the response on
    nSpecies - number of species to respond with
    '''
    response = SpeciesIDResponse()
    response.image_id = requestMsg.image_id
    for region in requestMsg.regions:
        singleId = SingleSpeciesId()
        singleId.bounding_box = region.bounding_box
        for speciesId in selector.ChooseNSpecies(nSpecies):
            singleId.best_species.append(
                SpeciesScore(species_id=speciesId, score=0.0))
        response.answers.append(singleId)
    response.header.stamp = rospy.Time.now()
    publisher.publish(response)
    def test_singleHit(self):
        # Should go straight to displaying the species info
        species_id = SingleSpeciesId(None, [SpeciesScore(2, 0.4)])

        SpeciesSelectionModule.speciesIdCallback(
            SpeciesIDResponse(3, [species_id]), self.module)

        self.checkSignalUpdate(3)

        d = self.module.GetOutputDict()
        self.assertEquals(d['state'], State.SPECIES_INFO_DISPLAYING)
        self.assertEquals(d['name'], 'SpeciesSelection')
        self.checkSpeciesInfo(self.speciesInfo[2], d['species'])
        self.assertEquals(d['user_chose'], False)
    def test_confidentScore(self):
        # A score was high enough to be confident, so we should just
        # display the info
        species_id = SingleSpeciesId(None, [SpeciesScore(0, 0.8)])

        SpeciesSelectionModule.speciesIdCallback(
            SpeciesIDResponse(3, [species_id]), self.module)

        self.checkSignalUpdate(3)

        d = self.module.GetOutputDict()
        self.assertEquals(d['state'], State.SPECIES_INFO_DISPLAYING)
        self.assertEquals(d['name'], 'SpeciesSelection')
        self.checkSpeciesInfo(self.speciesInfo[0], d['species'])
        self.assertEquals(d['user_chose'], False)
    def test_onlyOneValidScore(self):
        # Only one of the scores is above the min threshold, so we display
        species_id = SingleSpeciesId(
            None,
            [SpeciesScore(0, 0.3), SpeciesScore(3, 0.05)])

        SpeciesSelectionModule.speciesIdCallback(
            SpeciesIDResponse(3, [species_id]), self.module)

        self.checkSignalUpdate(3)

        d = self.module.GetOutputDict()
        self.assertEquals(d['state'], State.SPECIES_INFO_DISPLAYING)
        self.assertEquals(d['name'], 'SpeciesSelection')
        self.checkSpeciesInfo(self.speciesInfo[0], d['species'])
        self.assertEquals(d['user_chose'], False)
    def test_noBoundingBoxMultipleHits(self):
        species_id = SingleSpeciesId(
            None,
            [SpeciesScore(2, 0.4), SpeciesScore(3, 0.3)])

        SpeciesSelectionModule.speciesIdCallback(
            SpeciesIDResponse(3, [species_id]), self.module)

        self.checkSignalUpdate(3)

        d = self.module.GetOutputDict()
        self.assertEquals(d['state'], State.CANDIDATES_ARRIVED)
        self.assertEquals(d['name'], 'SpeciesSelection')
        self.assertTrue('bbox' not in d.keys())
        self.assertEquals(len(d['species_hits']), 3)
        self.checkSpeciesInfo(self.speciesInfo[2], d['species_hits'][0])
        self.checkSpeciesInfo(self.speciesInfo[3], d['species_hits'][1])
        self.checkSpeciesInfo(SpeciesSelectionModule.UNKNOWN_SPECIES,
                              d['species_hits'][2])
        self.assertEquals(d['user_chose'], False)
        self.assertEquals(d['idx'], 0)
    def setUp(self):
        TestCandidateArrival.setUp(self)

        # An initial image has already arrived
        SpeciesSelectionModule.imageCallback(ImageCaptured(3, None),
                                             self.module)

        self.signalMock.reset_mock()

        # The ID was made with 3 results
        species_id = SingleSpeciesId(
            None,
            [SpeciesScore(0, 0.5),
             SpeciesScore(3, 0.4),
             SpeciesScore(2, 0.3)])

        SpeciesSelectionModule.speciesIdCallback(
            SpeciesIDResponse(3, [species_id]), self.module)
        # Make sure State.CANDIDATES_ARRIVED worked
        self.module.GetOutputDict()

        self.signalMock.reset_mock()
 def test_differentImageId(self):
     SpeciesSelectionModule.speciesIdCallback(
         SpeciesIDResponse(4, [SingleSpeciesId(None, [])]), self.module)
     self.assertFalse(self.signalMock.called)
    def test_imageResponseBeforeImage(self):
        SpeciesSelectionModule.speciesIdCallback(
            SpeciesIDResponse(3, [SingleSpeciesId(None, [])]), self.module)

        self.assertFalse(self.signalMock.called)