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

Method iou

src/CVObjectDetection.cpp:249–270  ·  view source on GitHub ↗

Compute IOU between 2 boxes

Source from the content-addressed store, hash-verified

247
248// Compute IOU between 2 boxes
249bool CVObjectDetection::iou(cv::Rect pred_box, cv::Rect sort_box){
250 // Determine the (x, y)-coordinates of the intersection rectangle
251 int xA = std::max(pred_box.x, sort_box.x);
252 int yA = std::max(pred_box.y, sort_box.y);
253 int xB = std::min(pred_box.x + pred_box.width, sort_box.x + sort_box.width);
254 int yB = std::min(pred_box.y + pred_box.height, sort_box.y + sort_box.height);
255
256 // Compute the area of intersection rectangle
257 int interArea = std::max(0, xB - xA + 1) * std::max(0, yB - yA + 1);
258
259 // Compute the area of both the prediction and ground-truth rectangles
260 int boxAArea = (pred_box.width + 1) * (pred_box.height + 1);
261 int boxBArea = (sort_box.width + 1) * (sort_box.height + 1);
262
263 // Compute the intersection over union by taking the intersection
264 float iou = interArea / (float)(boxAArea + boxBArea - interArea);
265
266 // If IOU is above this value the boxes are very close (probably a variation of the same bounding box)
267 if(iou > 0.5)
268 return true;
269 return false;
270}
271
272// Get the names of the output layers
273std::vector<cv::String> CVObjectDetection::getOutputsNames(const cv::dnn::Net& net)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected