SDK for TUPU visual recognition service
- support file timestamp.
- CMake Errors fixed
- update to support MIME API, and
curl_formadd
API is deprecated - add debug rule in CMakeLists.txt
- Fixed bug in handling JSON result extraction
- Fixed signing bug on win
- Setting
CURLOPT_NOSIGNAL
as 1 for multi-threading
- Modified return value type of
performXXX
- Added
opErrorString
function to return string describing error code
- Fixed bug in reading private key on Windows
- Fixed test example syntax
- Bug fixed
- Update to distinguish methods for URL and path
- Update usage and example
- Correct examples for not mixing url and path in one request
- Supporting binary image data
- Add uid parameter
- openssl & openssl-devel (openssl-dev)
- libcurl & libcurl-devel (libcurl-dev), at least 7.56.0 version
- cmake
- opensll
- libcurl, at least 7.56.0 version
- cmake
$ cmake .
$ make
- lib/libtupu.a
- lib/libtupu.so
int main(int argc, char *argv[]) {
string secretId = "your_secret_id";
Recognition *rec = new Recognition("Path-of-Your-PKCS8-Private-Key");
//Set sub-user identifier for billing and statistics (optional feature)
//rec->setUID("user-bucket-xyz");
string imgUrl = "http://www.yourdomain.com/img/1.jpg";
string imgPath1 = "/home/user/img/1.jpg";
string imgPath2 = "/home/user/img/2.jpg";
vector<string> images1 = { imgUrl };
vector<string> images2 = { imgPath1, imgPath2 };
vector<string> tags = {"Funny"}; //number of tags may be less than number of images
string result;
long statusCode = 0;
OpCode rc = OPC_OK;
//Providing URLs of images with tags (optional)
rc = rec->performWithURL(secretId, result, &statusCode, images1, tags);
printResult(rc, statusCode, result);
//Providing paths of images without tags (optional)
rc = rec->performWithPath(secretId, result, &statusCode, images2);
printResult(rc, statusCode, result);
//Providing image binary and path
vector<TImage> images3;
loadImage(images3, imgPath2.c_str(), "Room102");
TImage timg;
timg.setPath(imgPath1);
timg.setTag("Room103");
images3.push_back(timg);
rc = rec->perform(secretId, images3, result, &statusCode);
printResult(rc, statusCode, result);
delete rec;
return 0;
}
void loadImage(vector<TImage> & images, const char * path, const char * tag)
{
ifstream f;
f.open(path, ios::binary);
if (f.good()) {
f.seekg(0, ios::end);
int length = f.tellg();
f.seekg(0, ios::beg);
char *buffer = new char[length];
f.read(buffer, length);
const char *fn = strrchr(path, '/');
fn = (fn == NULL) ? path : fn+1;
TImage img;
img.setBinary(buffer, length, fn);
if (tag != NULL)
img.setTag(tag);
images.push_back(img);
delete buffer;
}
f.close();
}
void printResult(OpCode rc, long statusCode, const string & result)
{
cout << "- Perform returns: " << rc << endl;
cout << "- HTTP Status Code: " << statusCode << endl;
cout << "- Result: " << endl << result << endl;
}
Perform a synchronous(blocking model) API call with URLs of images. This method can be called multiple times simultaneously.
secretId
: user's secret-id for accessing the APIresult
: recognition result in JSON string from serverstatusCode
: status code of responseimageURLs
: list of image URLstags
: list of tags for images (optional)
Returns 0
on success.
Perform a synchronous(blocking model) API call with local path of images. This method can be called multiple times simultaneously.
secretId
user's secret-id for accessing the APIresult
: recognition result in JSON string from serverstatusCode
: status code of responseimagePaths
: list of image local pathstags
: list of tags for images (optional)
Returns 0
on success.
Perform a synchronous API call and functions like the other 2 performXXX, but it also supports image binary.
- Please don't mix use of URL and path/binary in ONE call
- If using tag, please set tag for all images
- upgrade curl version to at least 7.56.0, and MIME API supported,
curl_formadd
deprecated - specify the
OPENSSL_ROOT_PATH
inCMakeLists.txt
secretId
: user's secret-id for accessing the APIimages
: list ofTImage
objectsresult
: recognition result in JSON string from serverstatusCode
: status code of response
Returns 0
on success.
Return string describing error code of Recognition::performXXX
const char * opErrorString(int err);