-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyKinect2 Integration wih OpenCV for YOLOv3 throws an error of : Number of input channels should be multiple of 3 but got 4 in function #104
Comments
for anyone wondering here's the code for the working YOLOv3 object detection with webcam : Load Yolo#net = cv2.dnn.readNet("weight/yolov3-tiny.weights", "cfg/yolov3-tiny.cfg") classes = [] Load Videocap = cv2.VideoCapture(0) #0 -> Webcam; "/path" cap = cv2.imread("masker01132.jpg")font = cv2.FONT_HERSHEY_SIMPLEX timeframe = time.time() while True:
cap.release() |
Here is the full code of my projects (big thanks to KonstantinosAng for mapper functions and guanming001 for the basic_2d examples)
from asyncore import read
from pykinect2.PyKinectV2 import *
from pykinect2 import PyKinectV2
from pykinect2 import PyKinectRuntime
import numpy as np
import cv2
import mapper
import time
net = cv2.dnn.readNet("yolov3-tiny_training_last.weights", "yolov3-tiny_testing (1).cfg")
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_OPENCL)
classes = []
with open("obj.names", "r") as f:
classes = [line.strip() for line in f.readlines()]
layer_names = net.getLayerNames()
output_layers = [layer_names[i-1] for i in net.getUnconnectedOutLayers()]
colors = np.random.uniform(0, 255, size=(len(classes), 3)) #Generate Random Color
font = cv2.FONT_HERSHEY_SIMPLEX
timeframe = time.time()
frame_id = 0
maskx=0
masky=0
no_maskx=0
no_masky=0
kinect = PyKinectRuntime.PyKinectRuntime(PyKinectV2.FrameSourceTypes_Color |
PyKinectV2.FrameSourceTypes_Depth)
depth_width, depth_height = kinect.depth_frame_desc.Width, kinect.depth_frame_desc.Height # Default: 512, 424
color_width, color_height = kinect.color_frame_desc.Width, kinect.color_frame_desc.Height # Default: 1920, 1080
while True:
kinect.close()
cv2.destroyAllWindows
here's the error for the code, i have done YOLOv3 with a webcam before and the data types seems to be the same as the variable color_img_resize, kinda confused here bcs apparently color_img_resize doesnt have the same input channels as the one with the webcam as an input
[ERROR:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\net_impl.cpp (1171) cv::dnn::dnn4_v20220524::Net::Impl::getLayerShapesRecursively OPENCV/DNN: [Convolution]:(conv_0): getMemoryShapes() throws exception. inputs=1 outputs=0/1 blobs=1
[ERROR:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\net_impl.cpp (1174) cv::dnn::dnn4_v20220524::Net::Impl::getLayerShapesRecursively input[0] = [ 1 4 320 320 ]
[ERROR:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\net_impl.cpp (1182) cv::dnn::dnn4_v20220524::Net::Impl::getLayerShapesRecursively blobs[0] = CV_32FC1 [ 16 3 3 3 ]
[ERROR:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\net_impl.cpp (1184) cv::dnn::dnn4_v20220524::Net::Impl::getLayerShapesRecursively Exception message: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\layers\convolution_layer.cpp:405: error: (-2:Unspecified error) Number of input Traceback (most recent call last):
File "cv2--kinect.py", line 62, in
outs = net.forward(output_layers)
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\layers\convolution_layer.cpp:405: error: (-2:Unspecified error) Number of input channels should be multiple of 3 but got 4 in function 'cv::dnn::ConvolutionLayerImpl::getMemoryShapes'
The text was updated successfully, but these errors were encountered: