Building JSONCPP inside Find-Object (easiest integration for Windows)

git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@390 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
matlabbe 2014-08-27 20:30:56 +00:00
parent c8192c4d0c
commit 2b229dcec2
7 changed files with 73 additions and 109 deletions

View File

@ -82,7 +82,6 @@ set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH
####### DEPENDENCIES #######
FIND_PACKAGE(OpenCV REQUIRED) # tested on 2.3.1
FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED) # tested on Qt4.8
FIND_PACKAGE(JSONCPP)
ADD_DEFINITIONS(-DQT_NO_KEYWORDS) # To avoid conflicts with boost signals used in ROS
####### OSX BUNDLE CMAKE_INSTALL_PREFIX #######
@ -223,9 +222,4 @@ MESSAGE(STATUS " CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
IF(APPLE)
MESSAGE(STATUS " BUILD_AS_BUNDLE = ${BUILD_AS_BUNDLE}")
ENDIF(APPLE)
IF(JSONCPP_FOUND)
MESSAGE(STATUS " With JSONCPP = YES")
ELSE()
MESSAGE(STATUS " With JSONCPP = NO (libjsoncpp not found)")
ENDIF()
MESSAGE(STATUS "--------------------------------------------")

View File

@ -99,7 +99,8 @@ void showUsage()
" --console Don't use the GUI (by default the camera will be\n"
" started automatically). Option --objects must also be\n"
" used with valid objects.\n"
" --objects \"path\" Directory of the objects to detect.\n"
" --object \"path\" Path to an object to detect.\n"
" --objects \"path\" Directory of the objects to detect (--object is ignored).\n"
" --config \"path\" Path to configuration file (default: %s).\n"
" --scene \"path\" Path to a scene image file.\n"
" --debug Show debug log.\n"
@ -107,11 +108,9 @@ void showUsage()
" --My/Parameter \"value\" Set find-Object's parameter (look --params for parameters' name).\n"
" It will override the one in --config. Example to set 4 threads:\n"
" $ find_object --General/threads 4\n"
" --help Show usage.\n", find_object::Settings::iniDefaultPath().toStdString().c_str());
if(find_object::JsonWriter::available())
{
printf(" --json \"path\" Path to an output JSON file (only in --console mode with --scene).\n");
}
" --json \"path\" Path to an output JSON file (only in --console mode with --scene).\n"
" --help Show usage.\n"
, find_object::Settings::iniDefaultPath().toStdString().c_str());
exit(-1);
}
@ -127,6 +126,7 @@ int main(int argc, char* argv[])
//////////////////////////
bool guiMode = true;
QString objectsPath = "";
QString objectPath = "";
QString scenePath = "";
QString configPath = find_object::Settings::iniDefaultPath();
QString jsonPath;
@ -159,6 +159,29 @@ int main(int argc, char* argv[])
}
continue;
}
if(strcmp(argv[i], "-object") == 0 ||
strcmp(argv[i], "--object") == 0)
{
++i;
if(i < argc)
{
objectPath = argv[i];
if(objectPath.contains('~'))
{
objectPath.replace('~', QDir::homePath());
}
if(!QFile(objectPath).exists())
{
UERROR("Object path not valid : %s", objectPath.toStdString().c_str());
showUsage();
}
}
else
{
showUsage();
}
continue;
}
if(strcmp(argv[i], "-scene") == 0 ||
strcmp(argv[i], "--scene") == 0)
{
@ -222,26 +245,23 @@ int main(int argc, char* argv[])
{
showUsage();
}
if(find_object::JsonWriter::available())
if(strcmp(argv[i], "-json") == 0 ||
strcmp(argv[i], "--json") == 0)
{
if(strcmp(argv[i], "-json") == 0 ||
strcmp(argv[i], "--json") == 0)
++i;
if(i < argc)
{
++i;
if(i < argc)
jsonPath = argv[i];
if(jsonPath.contains('~'))
{
jsonPath = argv[i];
if(jsonPath.contains('~'))
{
jsonPath.replace('~', QDir::homePath());
}
jsonPath.replace('~', QDir::homePath());
}
else
{
showUsage();
}
continue;
}
else
{
showUsage();
}
continue;
}
if(strcmp(argv[i], "--params") == 0)
{
@ -293,10 +313,8 @@ int main(int argc, char* argv[])
UINFO(" Objects path: \"%s\"", objectsPath.toStdString().c_str());
UINFO(" Scene path: \"%s\"", scenePath.toStdString().c_str());
UINFO(" Settings path: \"%s\"", configPath.toStdString().c_str());
if(find_object::JsonWriter::available())
{
UINFO(" JSON path: \"%s\"", jsonPath.toStdString().c_str());
}
UINFO(" JSON path: \"%s\"", jsonPath.toStdString().c_str());
for(find_object::ParametersMap::iterator iter= customParameters.begin(); iter!=customParameters.end(); ++iter)
{
UINFO(" Param \"%s\"=\"%s\"", iter.key().toStdString().c_str(), iter.value().toString().toStdString().c_str());
@ -328,6 +346,20 @@ int main(int argc, char* argv[])
UWARN("No objects loaded from \"%s\"", objectsPath.toStdString().c_str());
}
}
else if(!objectPath.isEmpty())
{
const find_object::ObjSignature * obj = findObject->addObject(objectPath);
if(obj)
{
++objectsLoaded;
findObject->updateObjects();
findObject->updateVocabulary();
}
else
{
UWARN("No object loaded from \"%s\"", objectsPath.toStdString().c_str());
}
}
cv::Mat scene;
if(!scenePath.isEmpty())
{
@ -388,7 +420,7 @@ int main(int argc, char* argv[])
UINFO("No objects detected. (%d ms)", time.elapsed());
}
if(!jsonPath.isEmpty() && find_object::JsonWriter::available())
if(!jsonPath.isEmpty())
{
find_object::JsonWriter::write(info, jsonPath);
UINFO("JSON written to \"%s\"", jsonPath.toStdString().c_str());

View File

@ -1,29 +0,0 @@
# - Find JSONCPP
# This module finds an installed JSONCPP package.
#
# It sets the following variables:
# JSONCPP_FOUND - Set to false, or undefined, if JSONCPP isn't found.
# JSONCPP_INCLUDE_DIRS - The JSONCPP include directory.
# JSONCPP_LIBRARIES - The JSONCPP library to link against.
FIND_PATH(JSONCPP_INCLUDE_DIRS json/features.h PATH_SUFFIXES jsoncpp)
FIND_LIBRARY(JSONCPP_LIBRARY NAMES jsoncpp)
IF (JSONCPP_INCLUDE_DIRS AND JSONCPP_LIBRARY)
SET(JSONCPP_FOUND TRUE)
ENDIF (JSONCPP_INCLUDE_DIRS AND JSONCPP_LIBRARY)
IF (JSONCPP_FOUND)
# show which JSONCPP was found only if not quiet
SET(JSONCPP_LIBRARIES ${JSONCPP_LIBRARY})
IF (NOT JSONCPP_FIND_QUIETLY)
MESSAGE(STATUS "Found JSONCPP: ${JSONCPP_LIBRARIES}")
ENDIF (NOT JSONCPP_FIND_QUIETLY)
ELSE (JSONCPP_FOUND)
# fatal error if JSONCPP is required but not found
IF (JSONCPP_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find JSONCPP (libjsoncpp)")
ENDIF (JSONCPP_FIND_REQUIRED)
ENDIF (JSONCPP_FOUND)

View File

@ -37,7 +37,6 @@ namespace find_object {
class FINDOBJECT_EXP JsonWriter
{
public:
static bool available();
static void write(const DetectionInfo & info, const QString & path);
};

View File

@ -58,6 +58,7 @@ SET(SRC_FILES
./utilite/UFile.cpp
./utilite/UConversion.cpp
./rtabmap/PdfPlot.cpp
./json/jsoncpp.cpp
${moc_srcs}
${moc_uis}
${srcs_qrc}
@ -77,18 +78,6 @@ SET(LIBRARIES
${OpenCV_LIBS}
)
IF(JSONCPP_FOUND)
SET(INCLUDE_DIRS
${INCLUDE_DIRS}
${JSONCPP_INCLUDE_DIRS}
)
SET(LIBRARIES
${LIBRARIES}
${JSONCPP_LIBRARIES}
)
ADD_DEFINITIONS("-DWITH_JSONCPP")
ENDIF(JSONCPP_FOUND)
#include files
INCLUDE_DIRECTORIES(${INCLUDE_DIRS})

View File

@ -31,24 +31,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QtCore/QFile>
#include <QtCore/QTextStream>
#ifdef WITH_JSONCPP
#include <json/writer.h>
#endif
#include "json/json.h"
namespace find_object {
bool JsonWriter::available()
{
#ifdef WITH_JSONCPP
return true;
#else
return false;
#endif
}
void JsonWriter::write(const DetectionInfo & info, const QString & path)
{
#ifdef WITH_JSONCPP
if(!path.isEmpty())
{
Json::Value root;
@ -121,9 +109,6 @@ void JsonWriter::write(const DetectionInfo & info, const QString & path)
out << styledWriter.write(root).c_str();
file.close();
}
#else
UERROR("Not built with JSON support!");
#endif
}
} // namespace find_object

View File

@ -39,11 +39,8 @@ void showUsage()
" \"out\" is the port to which the image is sent.\n"
" \"in\" is the port from which the detection is received.\n"
" Options:\n"
" --host #.#.#.# Set host address.\n");
if(find_object::JsonWriter::available())
{
printf(" --json \"path\" Path to an output JSON file.\n");
}
" --host #.#.#.# Set host address.\n"
" --json \"path\" Path to an output JSON file.\n");
exit(-1);
}
@ -114,22 +111,19 @@ int main(int argc, char * argv[])
continue;
}
if(find_object::JsonWriter::available())
if(strcmp(argv[i], "--json") == 0 || strcmp(argv[i], "-json") == 0)
{
if(strcmp(argv[i], "--json") == 0 || strcmp(argv[i], "-json") == 0)
++i;
if(i < argc)
{
++i;
if(i < argc)
{
jsonPath = argv[i];
}
else
{
printf("error parsing --json\n");
showUsage();
}
continue;
jsonPath = argv[i];
}
else
{
printf("error parsing --json\n");
showUsage();
}
continue;
}
printf("Unrecognized option: %s\n", argv[i]);
@ -234,7 +228,7 @@ int main(int argc, char * argv[])
printf("No objects detected.\n");
}
// write json
if(!jsonPath.isEmpty() && find_object::JsonWriter::available())
if(!jsonPath.isEmpty())
{
find_object::JsonWriter::write(response.info(), jsonPath);
printf("JSON written to \"%s\"\n", jsonPath.toStdString().c_str());