Changed JSON serialization/deserialization functions to static

This commit is contained in:
Matt Hill
2014-10-24 17:10:55 -04:00
parent 904ff09fa7
commit 1f64cfa029
4 changed files with 9 additions and 10 deletions

View File

@@ -59,11 +59,11 @@ AlprResults Alpr::recognize(unsigned char* pixelData, int bytesPerPixel, int img
std::string Alpr::toJson( AlprResults results ) std::string Alpr::toJson( AlprResults results )
{ {
return impl->toJson(results); return AlprImpl::toJson(results);
} }
AlprResults Alpr::fromJson(std::string json) { AlprResults Alpr::fromJson(std::string json) {
return impl->fromJson(json); return AlprImpl::fromJson(json);
} }

View File

@@ -114,8 +114,8 @@ class Alpr
AlprResults recognize(unsigned char* pixelData, int bytesPerPixel, int imgWidth, int imgHeight, std::vector<AlprRegionOfInterest> regionsOfInterest); AlprResults recognize(unsigned char* pixelData, int bytesPerPixel, int imgWidth, int imgHeight, std::vector<AlprRegionOfInterest> regionsOfInterest);
std::string toJson(const AlprResults results); static std::string toJson(const AlprResults results);
AlprResults fromJson(std::string json); static AlprResults fromJson(std::string json);
bool isLoaded(); bool isLoaded();

View File

@@ -79,8 +79,8 @@ class AlprImpl
void setTopN(int topn); void setTopN(int topn);
void setDefaultRegion(std::string region); void setDefaultRegion(std::string region);
std::string toJson( const AlprResults results ); static std::string toJson( const AlprResults results );
AlprResults fromJson(std::string json); static AlprResults fromJson(std::string json);
static std::string getVersion(); static std::string getVersion();
Config* config; Config* config;
@@ -99,7 +99,7 @@ class AlprImpl
std::vector<cv::Rect> convertRects(std::vector<AlprRegionOfInterest> regionsOfInterest); std::vector<cv::Rect> convertRects(std::vector<AlprRegionOfInterest> regionsOfInterest);
cJSON* createJsonObj(const AlprPlateResult* result); static cJSON* createJsonObj(const AlprPlateResult* result);
}; };

View File

@@ -18,7 +18,6 @@ using namespace std;
TEST_CASE( "JSON Serialization/Deserialization", "[json]" ) { TEST_CASE( "JSON Serialization/Deserialization", "[json]" ) {
Alpr alpr("us");
AlprResults origResults; AlprResults origResults;
origResults.epoch_time = getEpochTime(); origResults.epoch_time = getEpochTime();
origResults.img_width = 640; origResults.img_width = 640;
@@ -53,8 +52,8 @@ TEST_CASE( "JSON Serialization/Deserialization", "[json]" ) {
origResults.plates.push_back(apr); origResults.plates.push_back(apr);
std::string resultsJson = alpr.toJson(origResults); std::string resultsJson = Alpr::toJson(origResults);
AlprResults roundTrip = alpr.fromJson(resultsJson); AlprResults roundTrip = Alpr::fromJson(resultsJson);
REQUIRE( roundTrip.epoch_time == origResults.epoch_time ); REQUIRE( roundTrip.epoch_time == origResults.epoch_time );
REQUIRE( roundTrip.img_width == origResults.img_width ); REQUIRE( roundTrip.img_width == origResults.img_width );