Bounding Box
XxCODSQUADxX opened this issue · 14 comments
Just wondering if i might have a library incompatibility with this project. Im running opencv 4.7.0-dev. When i mkdi, cmake .. , make then run. The project will run but all of the bounding boxes are in the top left corner as a line. is there something else that I should be doing or is this just a library issue? There are not errors when building.
when i print out the float x,y,w,h they print 0
@XxCODSQUADxX Hmm, that's a weird one, can you confirm as to which model/resolution that you're using? I'm not really sure if I had an issue like that before... It's weird if everything is building and technically running but then if only the results are broken...
So i did a fresh clone of the repo and tried the yolov8s thats in the source from the provided pull. I only updated the folder location to point to the models provided form the repo. When running the image detection on the yolov8s.onnx it only detected one object and drew a line in the upper left corner. When i changed it to the yolov5s and ran it from the source folder it provided the expected bounding boxes on the image. Thanks for the help
Update.
After running through and trying to print out and make sure things were running correctly. For some reason the Yolov8s.onnx model in the source has the following results in dimensions:
Number of detections: 1
person
dimensions: 84
Prediction at dimension 0: 0
Prediction at dimension 1: 0
Prediction at dimension 2: 0
Prediction at dimension 3: 0
Prediction at dimension 4: 3.94355e-06
Prediction at dimension 5: 2.19224e-07
Prediction at dimension 6: 6.50607e-07
Prediction at dimension 7: 1.72118e-07
Prediction at dimension 8: 2.47182e-07
Prediction at dimension 9: 1.99928e-07
Prediction at dimension 10: 2.16225e-07
Prediction at dimension 11: 2.38081e-07
Prediction at dimension 12: 1.86343e-07
Prediction at dimension 13: 5.01186e-07
Prediction at dimension 14: 1.21312e-07
Prediction at dimension 15: 2.64759e-07
Prediction at dimension 16: 2.23364e-07
Prediction at dimension 17: 5.42412e-07
Prediction at dimension 18: 4.60981e-07
Prediction at dimension 19: 6.0006e-07
Prediction at dimension 20: 3.77104e-07
Prediction at dimension 21: 2.76848e-07
Prediction at dimension 22: 2.52651e-07
Prediction at dimension 23: 3.12084e-07
Prediction at dimension 24: 3.67804e-07
Prediction at dimension 25: 2.31763e-07
Prediction at dimension 26: 3.03532e-07
Prediction at dimension 27: 2.47612e-07
Prediction at dimension 28: 6.6135e-07
Prediction at dimension 29: 3.62342e-07
Prediction at dimension 30: 5.13051e-07
Prediction at dimension 31: 6.91298e-07
Prediction at dimension 32: 5.45912e-07
Prediction at dimension 33: 1.72616e-07
Prediction at dimension 34: 3.78626e-07
Prediction at dimension 35: 2.53361e-07
Prediction at dimension 36: 3.59142e-07
Prediction at dimension 37: 3.3341e-07
Prediction at dimension 38: 2.49368e-07
Prediction at dimension 39: 2.47113e-07
Prediction at dimension 40: 3.14948e-07
Prediction at dimension 41: 2.72881e-07
Prediction at dimension 42: 2.94053e-07
Prediction at dimension 43: 4.33597e-07
Prediction at dimension 44: 3.2724e-07
Prediction at dimension 45: 5.67956e-07
Prediction at dimension 46: 3.36183e-07
Prediction at dimension 47: 4.40321e-07
Prediction at dimension 48: 2.9471e-07
Prediction at dimension 49: 4.36217e-07
Prediction at dimension 50: 1.82865e-07
Prediction at dimension 51: 2.75829e-07
Prediction at dimension 52: 2.23339e-07
Prediction at dimension 53: 2.38576e-07
Prediction at dimension 54: 4.35349e-07
Prediction at dimension 55: 3.58061e-07
Prediction at dimension 56: 2.0851e-07
Prediction at dimension 57: 1.92231e-07
Prediction at dimension 58: 4.50098e-07
Prediction at dimension 59: 2.97252e-07
Prediction at dimension 60: 1.78071e-06
Prediction at dimension 61: 7.63515e-07
Prediction at dimension 62: 4.96421e-07
Prediction at dimension 63: 4.40507e-07
Prediction at dimension 64: 5.52886e-07
Prediction at dimension 65: 5.41447e-07
Prediction at dimension 66: 7.71225e-07
Prediction at dimension 67: 4.70259e-07
Prediction at dimension 68: 3.1304e-07
Prediction at dimension 69: 5.42676e-07
Prediction at dimension 70: 4.17839e-07
Prediction at dimension 71: 4.89881e-07
Prediction at dimension 72: 2.98958e-07
Prediction at dimension 73: 3.4793e-07
Prediction at dimension 74: 2.04577e-07
Prediction at dimension 75: 5.5002e-07
Prediction at dimension 76: 4.12568e-07
Prediction at dimension 77: 7.84322e-07
Prediction at dimension 78: 5.44867e-07
Prediction at dimension 79: 3.13286e-07
Prediction at dimension 80: 2.39933e-07
Prediction at dimension 81: 3.79888e-07
Prediction at dimension 82: 2.66539e-07
Prediction at dimension 83: 2.24147e-07
Number of detections: 1
person
I added
if (dimensions > rows) // Check if the shape[2] is more than shape[1] (yolov8)
{
yolov8 = true;
rows = outputs[0].size[2];
dimensions = outputs[0].size[1];
outputs[0] = outputs[0].reshape(1, dimensions);
cv::transpose(outputs[0], outputs[0]);
}
float *data = (float *)outputs[0].data;
// Add to confirm the dimensions
std::cout << "dimensions: " << dimensions << std::endl;
// Add this code to see what information is in the dimensions
for (int j = 0; j < dimensions; ++j)
{
std::cout << "Prediction at dimension " << j << ": " << data[j] << std::endl;
}
I am not sure yet what is causing the issue with the 0 for where the bounding box would be. The resolution is (640,480). Any ideas @JustasBart?
@XxCODSQUADxX Hmm no. I'm not sure, but perhaps try doing some testing with a square resolution? That is 640x640 or similar?
I tried a 640x640 to see if that happened to fix it. At this point i am not sure what else to do. It probably something to do with a my installation of opencv. So i'll wipe my opencv installation and start with a clean copy. Do you mind providing what version of opencv and cuda and cudnn you are running @JustasBart?
I am also facing the same issue on Linux Ubuntu 22 (WSL2).
However, it works fine on Windows (Win 10).
Both OpenCV 4.7
Edit:
It also works when I switch from CUDA Backend to the CPU.
CUDA 12.1 cuDNN 8.9.2 (arch 6.1 GTX 1080Ti)
I also have rebuilt OpenCV according to your instructions. (arch=6.1 config=Release)
I've tested both 640x640 and 640x480 shapes.
None of it seems to solve the issue.
Update:
Thanks just @JustasBart for that chart. I did a complete wipe and install of the opencv. It looks like there was an issue with the 4.7.0-dev and the opencv_contrib. To fix I downloaded the archived 4.7.0 opencv_contrib and opencv, followed the chart above and it fixed the issue. @TheYoungBeast my recommendation would be to try to do a fresh reinstall of just 4.7.0 for both of the opencv libraries.
@XxCODSQUADxX would you provide links to this "archived" version that you used?
I've rebuilt OpenCV at least 5 times, and the issue still exists.
@TheYoungBeast here are the opencv libraries that I used on the install.
https://github.com/opencv/opencv/archive/4.7.0.zip
unzip
https://github.com/opencv/opencv_contrib/archive/4.7.0.zip
It didn't work at first. It resulted in "[ WARN:0@0.052] global net_impl.cpp:174 setUpNet DNN module was not built with CUDA backend".
However, I solved the issue by setting the OPENCV_DNN_CUDA
option which is not included in the chart.
Problem solved. Thanks for your help!
Hi guys @TheYoungBeast @XxCODSQUADxX I've been rather busy lately, but I'm able to jump back onto this, so, where is this currently at? Are either of you still stuck with any of this or?
@JustasBart
It works fine. The problem seems to be resolved. I have also tested it in Docker container. Works fine.
ARG OPENCV_VERSION=4.7.0
ARG CUDA_ARCH_BIN="5.2 5.3 6.0 6.1 6.2 7.0 7.2 7.5 8.0 8.6"
[...]
# Install OpenCV
RUN cd /opt/ && \
wget https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip &&\
unzip $OPENCV_VERSION.zip &&\
rm $OPENCV_VERSION.zip &&\
wget https://github.com/opencv/opencv_contrib/archive/$OPENCV_VERSION.zip &&\
unzip ${OPENCV_VERSION}.zip &&\
rm ${OPENCV_VERSION}.zip &&\
mkdir /opt/opencv-${OPENCV_VERSION}/build && cd /opt/opencv-${OPENCV_VERSION}/build &&\
# Cmake configure
cmake \
-DOPENCV_EXTRA_MODULES_PATH=/opt/opencv_contrib-${OPENCV_VERSION}/modules \
-DWITH_CUDA=ON \
-DCUDA_ARCH_BIN=${CUDA_ARCH_BIN} \
-DCUDA_FAST_MATH=ON \
-DENABLE_FAST_MATH=ON \
-DCMAKE_BUILD_TYPE=RELEASE \
-DOPENCV_DNN_CUDA=ON \
-DBUILD_opencv_dnn=ON \
-DOPENCV_ENABLE_NONFREE=ON \
# Install path will be /usr/local/lib (lib is implicit)
.. && \
cmake --build . --target=install --config=Release -j 10
That's great, I'll close this for now, good luck! 🚀