Attention! This forum will be made read-only by Dec-20. Please migrate to https://forum.opencv.org. Most of existing active users should've received invitation by e-mail.
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach. It calculates a closeness factor for all contour pairs, sorts them in ascending order, then builds clusters of contours based on the closeness. The 4 main conditions for the pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a share, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle. I've implemented this in Java, so am looking for suggestions about the best way to share this method with the OpenCV community.

Original Image

Contours of pedestrian

ROI of pedestrian

click to hide/show revision 2
Add more pictures to illustrate the solution

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach. It calculates a closeness factor for all contour pairs, sorts them in ascending order, then builds clusters of contours based on the closeness. It creates partitions of distinct clusters.

The 4 main conditions for the pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a share, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle. rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method with the OpenCV community.

Image 1 Original Image

Image 2 Contours of pedestrian

Image 3 ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours.

The fifth image shows who the agglomeration helps to cluster these back into one object ROI.

Image 4 Contours of partially occluded vehicle

Image 5 ROI of vehicle

click to hide/show revision 3
More explanatory text

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach. It calculates a closeness factor for all contour pairs, sorts them in ascending order, then builds clusters of contours based on the closeness. It creates partitions of distinct clusters.

The 4 main conditions for the pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a share, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method with the OpenCV community.

Image 1 1: Original Image Original Image

Image 2 2: Contours with boundingRectangle Contours of pedestrian

Image 3 3: ROI derived (expanded) from boundingRectangle ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours.

The fifth image shows who the agglomeration helps to cluster these back into one object ROI.

Image 4 4: Contours of partially occluded vehicle Contours of partially occluded vehicle

Image 5 5: Vehicle with derived ROI ROI of vehicle

click to hide/show revision 4
Added more info on aglommerative clustering

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach. It calculates a closeness factor for all contour pairs, sorts them in ascending order, then builds clusters of contours based on the closeness. It creates partitions of distinct clusters.

The 4 main conditions for the pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a share, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method with the OpenCV community.

Image 1: Original Image Original Image

Image 2: Contours with boundingRectangle Contours of pedestrian

Image 3: ROI derived (expanded) from boundingRectangle ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours. The agglomerative clustering was performed, resulting in the boundingRectangle (thin red rectangle).

The fifth image shows who the agglomeration helps to cluster these back into one object ROI.how the boundingRectangle was used to derive the blue ROI (through simple expansion).

Image 4: Contours of partially occluded vehicle Contours of partially occluded vehicle

Image 5: Vehicle with derived ROI ROI of vehicle

click to hide/show revision 5
Explained the closeness factor in more detail

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach. It calculates approach;

a. Calculate a closeness factor for all contour pairs, sorts them pairs (distance between centers of contours minus the radii of both contours) b. Sort the pairs in ascending order, then order (start with the most obvious pairs to cluster first, to avoid having to spend CPU bandwidth in frequent restructuring of clusters) c. builds clusters of contours based on the closeness. It

This approach creates partitions of distinct clusters.clusters (e.g, contours associated with non-overlapping objects are partitioned into clusters associated with those objects respectively).

The 4 main conditions for the pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a share, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method with the OpenCV community.

Image 1: Original Image Original Image

Image 2: Contours with boundingRectangle Contours of pedestrian

Image 3: ROI derived (expanded) from boundingRectangle ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours. The agglomerative clustering was performed, resulting in the boundingRectangle (thin red rectangle).

The fifth image shows how the boundingRectangle was used to derive the blue ROI (through simple expansion).

Image 4: Contours of partially occluded vehicle Contours of partially occluded vehicle

Image 5: Vehicle with derived ROI ROI of vehicle

click to hide/show revision 6
Make a list of the Closeness factor explanation

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach;

a. Calculate a closeness factor for all contour pairs (distance between centers of contours minus the radii of both contours) contours)

b. Sort the pairs in ascending order (start with the most obvious pairs to cluster first, to avoid having to spend CPU bandwidth in frequent restructuring of clusters) clusters)

c. builds clusters of contours based on the closeness.

This approach creates partitions of distinct clusters (e.g, contours associated with non-overlapping objects are partitioned into clusters associated with those objects respectively).

The 4 main conditions for the pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a share, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method with the OpenCV community.

Image 1: Original Image Original Image

Image 2: Contours with boundingRectangle Contours of pedestrian

Image 3: ROI derived (expanded) from boundingRectangle ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours. The agglomerative clustering was performed, resulting in the boundingRectangle (thin red rectangle).

The fifth image shows how the boundingRectangle was used to derive the blue ROI (through simple expansion).

Image 4: Contours of partially occluded vehicle Contours of partially occluded vehicle

Image 5: Vehicle with derived ROI ROI of vehicle

click to hide/show revision 7
bolded key points in text

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach;approach;

a. Calculate a closeness factor for all contour pairs (distance between centers of contours minus the radii of both contours)

b. Sort the pairs in ascending order (start with the most obvious pairs to cluster first, to avoid having to spend CPU bandwidth in frequent restructuring of clusters)

c. builds clusters of contours based on the closeness.

This approach creates partitions of distinct clusters (e.g, contours associated with non-overlapping objects are partitioned into clusters associated with those objects respectively).

The 4 main conditions for the pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a share, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method with the OpenCV community.community.

Image 1: Original Image Original Image

Image 2: Contours with boundingRectangle Contours of pedestrian

Image 3: ROI derived (expanded) from boundingRectangle ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours. The agglomerative clustering was performed, resulting in the boundingRectangle (thin red rectangle).

The fifth image shows how the boundingRectangle was used to derive the blue ROI (through simple expansion).

Image 4: Contours of partially occluded vehicle Contours of partially occluded vehicle

Image 5: Vehicle with derived ROI ROI of vehicle

click to hide/show revision 8
Restructured the listing

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach;

a.

  • Calculate a closeness factor for all all contour pairs (distance between between centers of contours minus the radii radii of both contours)

    b.

  • Sort the pairs in ascending order
    (start with the most obvious pairs to to cluster first, to avoid having to
    spend CPU bandwidth in frequent
    restructuring of clusters)

    c. builds

  • Build clusters of contours based on the closeness.

    on the closeness.

This approach creates partitions of distinct clusters (e.g, contours associated with non-overlapping objects are partitioned into clusters associated with those objects respectively).

The 4 main conditions for the clustering the contour pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a share, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method with the OpenCV community.

Image 1: Original Image Original Image

Image 2: Contours with boundingRectangle Contours of pedestrian

Image 3: ROI derived (expanded) from boundingRectangle ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours. The agglomerative clustering was performed, resulting in the boundingRectangle (thin red rectangle).

The fifth image shows how the boundingRectangle was used to derive the blue ROI (through simple expansion).

Image 4: Contours of partially occluded vehicle vehicle, after clustering and bounded Contours of partially occluded vehicle

Image 5: Vehicle with derived ROI ROI of vehicle

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach;

  • Calculate a closeness factor for all contour pairs (distance between centers of contours minus the radii of both contours)

  • Sort the pairs in ascending order
    (start with the most obvious pairs to cluster first, to avoid having to
    spend CPU bandwidth in frequent
    restructuring of clusters)

  • Build clusters of contours based on the closeness.

This approach creates partitions of distinct clusters (e.g, contours associated with non-overlapping objects are partitioned into clusters associated with those objects respectively).

The 4 main conditions for clustering the contour pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a share, sharp, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method with the OpenCV community.

Image 1: Original Image Original Image

Image 2: Contours with boundingRectangle Contours of pedestrian

Image 3: ROI derived (expanded) from boundingRectangle ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours. The agglomerative clustering was performed, resulting in the boundingRectangle (thin red rectangle).

The fifth image shows how the boundingRectangle was used to derive the blue ROI (through simple expansion).

Image 4: Contours of partially occluded vehicle, after clustering and bounded Contours of partially occluded vehicle

Image 5: Vehicle with derived ROI ROI of vehicle

click to hide/show revision 10
Added four more images

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach;

  • Calculate a closeness factor for all contour pairs (distance between centers of contours minus the radii of both contours)

  • Sort the pairs in ascending order
    (start with the most obvious pairs to cluster first, to avoid having to
    spend CPU bandwidth in frequent
    restructuring of clusters)

  • Build clusters of contours based on the closeness.

This approach creates partitions of distinct clusters (e.g, contours associated with non-overlapping objects are partitioned into clusters associated with those objects respectively).

The 4 main conditions for clustering the contour pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a sharp, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method with the OpenCV community.

Image 1: Original Image Original Image

Image 2: Contours with boundingRectangle Contours of pedestrian

Image 3: ROI derived (expanded) from boundingRectangle ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours. The agglomerative clustering was performed, resulting in the boundingRectangle (thin red rectangle).

The fifth image shows how the boundingRectangle was used to derive the blue ROI (through simple expansion).

Image 4: Contours of partially occluded vehicle, after clustering and bounded Contours of partially occluded vehicle

Image 5: Vehicle with derived ROI ROI of vehicle

Image 6: Dark vehicle in snow with many small contours clustered

Image 7: Dark vehicle in snow with ROI

Image 8: Dark vehicle in shade with few contours discovered, but clustered to reveal outline Dark Vehicle in shade

Image 9: ROI of dark vehicle in shade ROI of dark vehicle in shade

click to hide/show revision 11
Added explanation of 'solitary' contours that are not paired with other close contours

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach;

  • Calculate a closeness factor for all all contour pairs (distance between between centers of contours minus the radii radii of both contours)

  • Sort the pairs in ascending order
    (start with the most obvious pairs to to cluster first, to avoid having to
    spend CPU bandwidth in frequent
    restructuring of clusters)

  • Build clusters of contours based on on the closeness.

  • Add clusters for 'solitary' clusters, after evaluating for size. With a very good background detection, some objects might only one one contour (i.e., don't throw the baby out with the bathwater).

This approach creates partitions of distinct clusters (e.g, contours associated with non-overlapping objects are partitioned into clusters associated with those objects respectively).

The 4 main conditions for clustering the contour pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a sharp, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method with the OpenCV community.

Image 1: Original Image Original Image

Image 2: Contours with boundingRectangle Contours of pedestrian

Image 3: ROI derived (expanded) from boundingRectangle ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours. The agglomerative clustering was performed, resulting in the boundingRectangle (thin red rectangle).

The fifth image shows how the boundingRectangle was used to derive the blue ROI (through simple expansion).

Image 4: Contours of partially occluded vehicle, after clustering and bounded Contours of partially occluded vehicle

Image 5: Vehicle with derived ROI ROI of vehicle

Image 6: Dark vehicle in snow with many small contours clustered

Image 7: Dark vehicle in snow with ROI

Image 8: Dark vehicle in shade with few contours discovered, but clustered to reveal outline Dark Vehicle in shade

Image 9: ROI of dark vehicle in shade ROI of dark vehicle in shade

click to hide/show revision 12
gave credit for the idea to Guanta

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach, thanks to the thoughtful suggestion by @Guanta ;

  • Calculate a closeness factor for all contour pairs (distance between centers of contours minus the radii of both contours)

  • Sort the pairs in ascending order (start with the most obvious pairs to cluster first, to avoid having to spend CPU bandwidth in frequent restructuring of clusters)

  • Build clusters of contours based on the closeness.

  • Add clusters for 'solitary' clusters, after evaluating for size. With a very good background detection, some objects might only one one contour (i.e., don't throw the baby out with the bathwater).

This approach creates partitions of distinct clusters (e.g, contours associated with non-overlapping objects are partitioned into clusters associated with those objects respectively).

The 4 main conditions for clustering the contour pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a sharp, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method with the OpenCV community.

Image 1: Original Image Original Image

Image 2: Contours with boundingRectangle Contours of pedestrian

Image 3: ROI derived (expanded) from boundingRectangle ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours. The agglomerative clustering was performed, resulting in the boundingRectangle (thin red rectangle).

The fifth image shows how the boundingRectangle was used to derive the blue ROI (through simple expansion).

Image 4: Contours of partially occluded vehicle, after clustering and bounded Contours of partially occluded vehicle

Image 5: Vehicle with derived ROI ROI of vehicle

Image 6: Dark vehicle in snow with many small contours clustered

Image 7: Dark vehicle in snow with ROI

Image 8: Dark vehicle in shade with few contours discovered, but clustered to reveal outline Dark Vehicle in shade

Image 9: ROI of dark vehicle in shade ROI of dark vehicle in shade

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach, thanks to the thoughtful suggestion by @Guanta ;

  • Calculate a closeness factor for all contour pairs (distance between centers of contours minus the radii of both contours)

  • Sort the pairs in ascending order (start with the most obvious pairs to cluster first, to avoid having to spend CPU bandwidth in frequent restructuring of clusters)

  • Build clusters of contours based on the closeness.

  • Add clusters for 'solitary' clusters, after evaluating for size. With a very good background detection, some objects might only one result in one contour (i.e., don't throw the baby out with the bathwater).

This approach creates partitions of distinct clusters (e.g, contours associated with non-overlapping objects are partitioned into clusters associated with those objects respectively).

The 4 main conditions for clustering the contour pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a sharp, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn.drawn as a thin red bounding rectangle.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method and code with the OpenCV community.

Image 1: Original Image Original Image

Image 2: Contours with boundingRectangle Contours of pedestrian

Image 3: ROI derived (expanded) from boundingRectangle ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours. The agglomerative clustering was performed, resulting in the boundingRectangle (thin red rectangle).

The fifth image shows how the boundingRectangle was used to derive the blue ROI (through simple expansion).

Image 4: Contours of partially occluded vehicle, after clustering and bounded Contours of partially occluded vehicle

Image 5: Vehicle with derived ROI ROI of vehicle

Image 6: Dark vehicle in snow with many small contours clustered

Image 7: Dark vehicle in snow with ROI

Image 8: Dark vehicle in shade with few contours discovered, but clustered to reveal outline Dark Vehicle in shade

Image 9: ROI of dark vehicle in shade ROI of dark vehicle in shade

click to hide/show revision 14
corrected "clusters" to "contours in one spot

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach, thanks to the thoughtful suggestion by @Guanta ;

  • Calculate a closeness factor for all contour pairs (distance between centers of contours minus the radii of both contours)

  • Sort the pairs in ascending order (start with the most obvious pairs to cluster first, to avoid having to spend CPU bandwidth in frequent restructuring of clusters)

  • Build clusters of contours based on the closeness.

  • Add clusters for 'solitary' clusters, contours, after evaluating for size. With a very good background detection, some objects might only result in one contour (i.e., don't throw the baby out with the bathwater).bathwater by only looking at contour pairs).

This approach creates partitions of distinct clusters (e.g, contours associated with non-overlapping objects are partitioned into clusters associated with those objects respectively).

The 4 main conditions for clustering the contour pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a sharp, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn as a thin red bounding rectangle.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method and code with the OpenCV community.

Image 1: Original Image Original Image

Image 2: Contours with boundingRectangle Contours of pedestrian

Image 3: ROI derived (expanded) from boundingRectangle ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours. The agglomerative clustering was performed, resulting in the boundingRectangle (thin red rectangle).

The fifth image shows how the boundingRectangle was used to derive the blue ROI (through simple expansion).

Image 4: Contours of partially occluded vehicle, after clustering and bounded Contours of partially occluded vehicle

Image 5: Vehicle with derived ROI ROI of vehicle

Image 6: Dark vehicle in snow with many small contours clustered

Image 7: Dark vehicle in snow with ROI

Image 8: Dark vehicle in shade with few contours discovered, but clustered to reveal outline Dark Vehicle in shade

Image 9: ROI of dark vehicle in shade ROI of dark vehicle in shade

click to hide/show revision 15
added condition reference

The way I solved the problem of aggregating contours with a high degree of affinity (e.g., multiple contours that describe a single object) was to implement a partitioned, non-hierarchical agglomerative clustering approach, thanks to the thoughtful suggestion by @Guanta ;

  • Calculate a closeness factor for all contour pairs (distance between centers of contours minus the radii of both contours)

  • Sort the pairs in ascending order (start with the most obvious pairs to cluster first, to avoid having to spend CPU bandwidth in frequent restructuring of clusters)

  • Build clusters of contours based on the closeness.closeness (see 4 conditions below).

  • Add clusters for 'solitary' contours, after evaluating for size. With a very good background detection, some objects might only result in one contour (i.e., don't throw the baby out with the bathwater by only looking at contour pairs).

This approach creates partitions of distinct clusters (e.g, contours associated with non-overlapping objects are partitioned into clusters associated with those objects respectively).

The 4 main conditions for clustering the contour pairs are;

  1. Neither are in a cluster yet, so a cluster is created and both are added to it.
  2. Both are already in the same cluster. Nothing else needs to be done for this pair.
  3. One contour is in a cluster, the other is not. The one that is not is appended to the cluster of the one that is.
  4. One contour is in one cluster, the other contour is in a different cluster. One cluster then absorbs the other, which is then removed.

The overall area of a cluster is examined to see if it is greater than the threshold size (we don't want to capture images of birds or cats if we actually want to trigger on people or vehicles).

Since the contours frequently do not completely encompass a moving object, an additional amount of image can be defined (e.g., 25% more on each direction of the rectangle) depending upon a number of tuning factors.

The first picture is the original image. While the black coat against the snow gives a sharp, well-defined edge, the dark mulch gives little contrast, and hence a number of contours for the pedestrian are the result.

The second image shows both the contours that were generated, as well as the cluster that was calculated and drawn as a thin red bounding rectangle.

The third image shows the ROI, which in this case was derived from the cluster outline with an additional 25% additional area on each side of the rectangle.

I've implemented this in Java, so am looking for suggestions about the best way to share this method and code with the OpenCV community.

Image 1: Original Image Original Image

Image 2: Contours with boundingRectangle Contours of pedestrian

Image 3: ROI derived (expanded) from boundingRectangle ROI of pedestrian

The fourth image is of a more distant moving object partially occluded by fence boards, with consequent fragmented contours. The agglomerative clustering was performed, resulting in the boundingRectangle (thin red rectangle).

The fifth image shows how the boundingRectangle was used to derive the blue ROI (through simple expansion).

Image 4: Contours of partially occluded vehicle, after clustering and bounded Contours of partially occluded vehicle

Image 5: Vehicle with derived ROI ROI of vehicle

Image 6: Dark vehicle in snow with many small contours clustered

Image 7: Dark vehicle in snow with ROI

Image 8: Dark vehicle in shade with few contours discovered, but clustered to reveal outline Dark Vehicle in shade

Image 9: ROI of dark vehicle in shade ROI of dark vehicle in shade