Skip to content

Commit

Permalink
Adding support for Streamlabs Desktop Virtual Webcam
Browse files Browse the repository at this point in the history
Streamlabs Desktop has the same issue in opencv#19746.
This fixes it using opencv#23460 method.

Add getMatInblob function

e
  • Loading branch information
DeePingXian authored and LaurentBerger committed Sep 8, 2023
1 parent 8ad5eb5 commit fc18451
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 2 deletions.
7 changes: 7 additions & 0 deletions modules/dnn/include/opencv2/dnn/all_layers.hpp
Expand Up @@ -1101,6 +1101,13 @@ CV__DNN_INLINE_NS_BEGIN
static Ptr<LayerNormLayer> create(const LayerParams& params);
};

class CV_EXPORTS ExpandLayer : public Layer
{
public:

static Ptr<ExpandLayer> create(const LayerParams& params);
};

//! @}
//! @}
CV__DNN_INLINE_NS_END
Expand Down
1 change: 1 addition & 0 deletions modules/dnn/include/opencv2/dnn/dnn.hpp
Expand Up @@ -1266,6 +1266,7 @@ CV__DNN_INLINE_NS_BEGIN
*/
CV_EXPORTS_W void imagesFromBlob(const cv::Mat& blob_, OutputArrayOfArrays images_);


/** @brief Convert all weights of Caffe network to half precision floating point.
* @param src Path to origin model from Caffe framework contains single
* precision floating point weights (usually has `.caffemodel` extension).
Expand Down
1 change: 1 addition & 0 deletions modules/dnn/src/dnn_utils.cpp
Expand Up @@ -260,5 +260,6 @@ void imagesFromBlob(const cv::Mat& blob_, OutputArrayOfArrays images_)
}



CV__DNN_INLINE_NS_END
}} // namespace cv::dnn
3 changes: 3 additions & 0 deletions modules/dnn/src/init.cpp
Expand Up @@ -227,6 +227,9 @@ void initializeLayerFactory()
CV_DNN_REGISTER_LAYER_CLASS(PermuteInt8, PermuteLayer);
CV_DNN_REGISTER_LAYER_CLASS(ReorgInt8, ReorgLayer);
CV_DNN_REGISTER_LAYER_CLASS(ShuffleChannelInt8, ShuffleChannelLayer);

CV_DNN_REGISTER_LAYER_CLASS(Expand, ExpandLayer);

}

CV__DNN_INLINE_NS_END
Expand Down
40 changes: 39 additions & 1 deletion modules/dnn/src/onnx/onnx_importer.cpp
Expand Up @@ -2396,7 +2396,28 @@ void ONNXImporter::parseExpand(LayerParams& layerParams, const opencv_onnx::Node
inpShape = shape(blob);
}
}
//// NEW
LayerParams constParams;
constParams.name = layerParams.name + "/const";
CV_Assert(layer_id.find(constParams.name) == layer_id.end());
constParams.type = "Const";

Mat inp = Mat::ones(targetShape.size(), &targetShape[0], CV_32F);
constParams.blobs.push_back(inp);

opencv_onnx::NodeProto proto;
proto.add_output(constParams.name);
addLayer(constParams, proto);

layerParams.type = "Expand";
node_proto.set_input(0, constParams.name);
node_proto.set_input(1, input0);
// CV_Error(Error::StsNotImplemented, "Unsupported Expand op");
addLayer(layerParams, node_proto);
return;
/// <summary>
/// END NEW
/// </summary>
String srcName = input0;
// Unsqueeze and repeat along new axis
if (targetShape.size() > inpShape.size())
Expand Down Expand Up @@ -2498,7 +2519,24 @@ void ONNXImporter::parseExpand(LayerParams& layerParams, const opencv_onnx::Node
layerParams.type = "Identity";
}
else
CV_Error(Error::StsNotImplemented, "Unsupported Expand op");
{
LayerParams constParams;
constParams.name = layerParams.name + "/const";
CV_Assert(layer_id.find(constParams.name) == layer_id.end());
constParams.type = "Const";

Mat inp = Mat::ones(targetShape.size(), &targetShape[0], CV_32F);
constParams.blobs.push_back(inp);

opencv_onnx::NodeProto proto;
proto.add_output(constParams.name);
addLayer(constParams, proto);

layerParams.type = "Expand";
node_proto.set_input(0, constParams.name);
node_proto.set_input(1, srcName);
// CV_Error(Error::StsNotImplemented, "Unsupported Expand op");
}
addLayer(layerParams, node_proto);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/videoio/src/cap_dshow.cpp
Expand Up @@ -2771,7 +2771,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
if(customSize){
DebugPrintOut("SETUP: Default Format is set to %ix%i\n", currentWidth, currentHeight);

if (strcmp("OBS Virtual Camera", VD->nDeviceName) == 0)
if (strcmp("OBS Virtual Camera", VD->nDeviceName) == 0 || strcmp("Streamlabs Desktop Virtual Webcam", VD->nDeviceName) == 0)
{
// OBS Virtual Camera always returns S_OK on SetFormat(), even if it doesn't support
// the actual format. So we have to choose a format that it supports manually, e.g. NV12.
Expand Down

0 comments on commit fc18451

Please sign in to comment.