0

So I am working with Python 2.7.9 trying to use a pose recognition code, but I keep getting the following error telling me my blob size is zero. What would be the process for fixing such an issue?



`import cv2

# Load the pre-trained Caffe model
net = cv2.dnn.readNetFromCaffe('pose_deploy.txt', 'pose_iter_440000.caffemodel')
#net = cv2.dnn.readNetFromCaffe('deploy.prototxt.txt', 'pose_iter_440000.caffemodel')
# Load the image
im = cv2.imread('man_standing1.jpg')

# Specify the input size for the network
input_width = 368
input_height = 368
image=cv2.resize(im,(input_width,input_height),interpolation=cv2.INTER_AREA)
cv2.imshow('resized image', image)
cv2.waitKey()
# Preprocess the image
#blob = cv2.dnn.blobFromImage(image, 1.0, (input_width, input_height), (127.5, 127.5, 127.5), swapRB=True, crop=False)

blob = cv2.dnn.blobFromImage(image, 1.0, (input_width, input_height), (127.5, 127.5, 127.5), swapRB=True, crop=False)


print(blob.shape)
# Set the input to the network
net.setInput(blob)

# Forward pass through the network to get the output
output = net.forward()

# Get the dimensions of the image
image_height, image_width, _ = image.shape

# Iterate over the detected keypoints
for i in range(output.shape[1]):
    # Get the confidence score of the keypoint detection
    confidence = output[0, i, 0, 2]

    # If the confidence score is above a certain threshold, draw the keypoint on the image
    if confidence > 0.5:
        # Get the x and y coordinates of the keypoint
        x = int(output[0, i, 0, 3] * image_width)
        y = int(output[0, i, 0, 4] * image_height)

        # Draw a circle at the keypoint position
        cv2.circle(image, (x, y), 5, (0, 255, 0), -1)

# Display the image with keypoints
cv2.imshow('Pose Detection', image)
cv2.waitKey(0)
cv2.destroyAllWindows()`

The shell error I get is:

`>>> ================================ RESTART ================================
>>> 
(1L, 3L, 368L, 368L)

Traceback (most recent call last):
  File "C:\Users\dibblejp\Desktop\naoqi libraries\lib\aa_pose_recognition27.py", line 30, in <module>
    output = net.forward()
error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\dnn\src\layers\convolution_layer.cpp:310: error: (-215:Assertion failed) blobs.size() != 0 in function 'cv::dnn::ConvolutionLayerImpl::getMemoryShapes'
`

I made sure that the caffe models, and the image were in the same directory as the program file but it still gives me this error.

jostiff
  • 1
  • 1

0 Answers0