MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / LoadBoxData

Method LoadBoxData

src/TrackedObjectBBox.cpp:235–291  ·  view source on GitHub ↗

Load the bounding-boxes information from the protobuf file

Source from the content-addressed store, hash-verified

233
234// Load the bounding-boxes information from the protobuf file
235bool TrackedObjectBBox::LoadBoxData(std::string inputFilePath)
236{
237 using std::ios;
238
239 // Variable to hold the loaded data
240 pb_tracker::Tracker bboxMessage;
241
242 // Read the existing tracker message.
243 std::fstream input(inputFilePath, ios::in | ios::binary);
244
245 // Check if it was able to read the protobuf data
246 if (!bboxMessage.ParseFromIstream(&input))
247 {
248 std::cerr << "Failed to parse protobuf message." << std::endl;
249 return false;
250 }
251
252 this->clear();
253
254 // Iterate over all frames of the saved message
255 for (size_t i = 0; i < bboxMessage.frame_size(); i++)
256 {
257 // Get data of the i-th frame
258 const pb_tracker::Frame &pbFrameData = bboxMessage.frame(i);
259
260 // Get frame number
261 size_t frame_number = pbFrameData.id();
262
263 // Get bounding box data from current frame
264 const pb_tracker::Frame::Box &box = pbFrameData.bounding_box();
265
266 float width = box.x2() - box.x1();
267 float height = box.y2() - box.y1();
268 float cx = box.x1() + width/2;
269 float cy = box.y1() + height/2;
270 float angle = 0.0;
271
272
273 if ( (cx >= 0.0) && (cy >= 0.0) && (width >= 0.0) && (height >= 0.0) )
274 {
275 // The bounding-box properties are valid, so add it to the BoxVec map
276 this->AddBox(frame_number, cx, cy, width, height, angle);
277 }
278 }
279
280 // Show the time stamp from the last update in tracker data file
281 if (bboxMessage.has_last_updated())
282 {
283 std::cout << " Loaded Data. Saved Time Stamp: "
284 << TimeUtil::ToString(bboxMessage.last_updated()) << std::endl;
285 }
286
287 // Delete all global objects allocated by libprotobuf.
288 google::protobuf::ShutdownProtobufLibrary();
289
290 return true;
291}
292

Callers 1

SetJsonValueMethod · 0.80

Calls 2

clearMethod · 0.95
AddBoxMethod · 0.95

Tested by

no test coverage detected