| 299 | } |
| 300 | |
| 301 | bool CVObjectDetection::SaveObjDetectedData(){ |
| 302 | // Create tracker message |
| 303 | pb_objdetect::ObjDetect objMessage; |
| 304 | |
| 305 | //Save class names in protobuf message |
| 306 | for(int i = 0; i<classNames.size(); i++){ |
| 307 | std::string* className = objMessage.add_classnames(); |
| 308 | className->assign(classNames.at(i)); |
| 309 | } |
| 310 | |
| 311 | // Iterate over all frames data and save in protobuf message |
| 312 | for(std::map<size_t,CVDetectionData>::iterator it=detectionsData.begin(); it!=detectionsData.end(); ++it){ |
| 313 | CVDetectionData dData = it->second; |
| 314 | pb_objdetect::Frame* pbFrameData; |
| 315 | AddFrameDataToProto(objMessage.add_frame(), dData); |
| 316 | } |
| 317 | |
| 318 | // Add timestamp |
| 319 | *objMessage.mutable_last_updated() = TimeUtil::SecondsToTimestamp(time(NULL)); |
| 320 | |
| 321 | { |
| 322 | // Write the new message to disk. |
| 323 | std::fstream output(protobuf_data_path, ios::out | ios::trunc | ios::binary); |
| 324 | if (!objMessage.SerializeToOstream(&output)) { |
| 325 | cerr << "Failed to write protobuf message." << endl; |
| 326 | return false; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | // Delete all global objects allocated by libprotobuf. |
| 331 | google::protobuf::ShutdownProtobufLibrary(); |
| 332 | |
| 333 | return true; |
| 334 | |
| 335 | } |
| 336 | |
| 337 | // Add frame object detection into protobuf message. |
| 338 | void CVObjectDetection::AddFrameDataToProto(pb_objdetect::Frame* pbFrameData, CVDetectionData& dData) { |
no outgoing calls
no test coverage detected