Skip to content

Commit

Permalink
Add the findFile method
Browse files Browse the repository at this point in the history
  • Loading branch information
martinaxgloria authored and Nicogene committed Mar 29, 2023
1 parent 1ca1865 commit ceb29d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/modules/ergoCubEmotions/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ num_expressions 4
[expression_0]
name angry
type image
file /expressions/images/exp_img_0.png
file expressions/images/exp_img_0.png

[expression_1]
name happy
type image
file /expressions/images/exp_img_1.png
file expressions/images/exp_img_1.png

[expression_2]
name neutral
type image
file /expressions/images/exp_img_2.png
file expressions/images/exp_img_2.png

[expression_3]
name shy
type image
file /expressions/images/exp_img_3.png
file expressions/images/exp_img_3.png
23 changes: 7 additions & 16 deletions src/modules/ergoCubEmotions/ergoCubEmotions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,8 @@ bool ErgoCubEmotions::configure(ResourceFinder& rf)
{
cmdPort.open("/ergoCubEmotions/rpc");
attach(cmdPort);

auto filePath = rf.findPath("config.ini");
auto last_slash_idx = filePath.rfind('/');
if (std::string::npos != last_slash_idx)
{
path = filePath.substr(0, last_slash_idx);
}

else {
yError() <<"Cannot find config.ini";
return false;
}


this->rf=&rf;
Bottle &bGroup = rf.findGroup("general");
nexpressions = bGroup.find("num_expressions").asInt32();
for (int i = 0; i < nexpressions; i++)
Expand All @@ -65,10 +54,11 @@ bool ErgoCubEmotions::configure(ResourceFinder& rf)

namedWindow("emotion", WND_PROP_FULLSCREEN);
setWindowProperty("emotion", WND_PROP_FULLSCREEN, WINDOW_FULLSCREEN);
Mat start_img = imread(path + "/expressions/images/exp_img_2.png");
path = rf.findFile("expressions/images/exp_img_2.png");
Mat start_img = imread(path);
if(start_img.empty())
{
yError() << "Could not read the image in"<<path;
yError() << "Could not read the image";
return false;
}

Expand Down Expand Up @@ -104,7 +94,8 @@ bool ErgoCubEmotions::setEmotion(const std::string& command)
{
if(it->first.second == "image")
{
Mat img = imread(path + it->second);
path = rf->findFile(it->second);
Mat img = imread(path);
if(img.empty())
{
yDebug() << "Could not read the image!";
Expand Down
3 changes: 2 additions & 1 deletion src/modules/ergoCubEmotions/ergoCubEmotions.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ constexpr yarp::conf::vocab32_t EMOTION_VOCAB_CUN = yarp::os::createVocab32('c'

// ergoCubEmotions class definition
class ErgoCubEmotions : public yarp::os::RFModule, public ergoCubEmotions_IDL {
private:
protected:
yarp::os::ResourceFinder *rf;

public:
ErgoCubEmotions();
Expand Down

0 comments on commit ceb29d8

Please sign in to comment.