Help Needed: OpenCV Error While Implementing Object Detection on BeagleBone AI

@Middleware & OS @MCU, MPU & Firmware @Helper Hey guys, am working on an object detection project using the BeagleBone AI with Debian as the operating system and Ethernet as the protocol. I have encountered an error while implementing the code. Here are the steps I have installed Debian OS on the BeagleBone AI, set up the Ethernet connection for communication, installed the necessary libraries and dependencies for object detection. And I got the error
OpenCV Error: Unspecified error (Can't open darknet config file: yolov3.cfg) in cv::dnn::ReadDarknetFromCfgFile, file /home/user/opencv/modules/dnn/src/darknet/darknet_io.cpp, line 517
OpenCV Error: Unspecified error (Can't open darknet config file: yolov3.cfg) in cv::dnn::ReadDarknetFromCfgFile, file /home/user/opencv/modules/dnn/src/darknet/darknet_io.cpp, line 517
Then I tried verifying that the yolov3.cfg file is present in the correct directory, checked the file permissions and made sure it is readable, double-checked the file name and extension for any typos. But error still persists, and I am unable to load the pre-trained model for object detection. here's my code
import cv2
import numpy as np

# Load the pre-trained model
model = cv2.dnn.readNetFromDarknet('yolov3.cfg', 'yolov3.weights')

# Load the image
image = cv2.imread('image.jpg')

# Preprocess the image
blob = cv2.dnn.blobFromImage(image, 1/255, (416, 416), swapRB=True, crop=False)

# Set the input
model.setInput(blob)

# Forward pass through the network
output_layers_names = model.getUnconnectedOutLayersNames()
layer_outputs = model.forward(output_layers_names)
import cv2
import numpy as np

# Load the pre-trained model
model = cv2.dnn.readNetFromDarknet('yolov3.cfg', 'yolov3.weights')

# Load the image
image = cv2.imread('image.jpg')

# Preprocess the image
blob = cv2.dnn.blobFromImage(image, 1/255, (416, 416), swapRB=True, crop=False)

# Set the input
model.setInput(blob)

# Forward pass through the network
output_layers_names = model.getUnconnectedOutLayersNames()
layer_outputs = model.forward(output_layers_names)
Solution:
My code works perfectly now 👍
Jump to solution
5 Replies
wafa_ath
wafa_ath6mo ago
It is either a problem in the path or in the version of openCv , try using the absolute path just to make sure of directory
Enthernet Code
Enthernet Code6mo ago
I have specified the exact path in code, but I would try updating my openCv version as u suggested
wafa_ath
wafa_ath6mo ago
make sure it suited your version of python too
Enthernet Code
Enthernet Code6mo ago
Thanks @wafa_ath the problem was my openCv version, I was using openCv 2.4 instead of openCv 3.4 and above
Solution
Enthernet Code
Enthernet Code6mo ago
My code works perfectly now 👍
Want results from more Discord servers?
Add your server