【问题标题】:C# EmguCV Mat.PtrC# EmguCV Mat.Ptr
【发布时间】:2018-06-10 03:35:56
【问题描述】:

我正在尝试将 C++ OpenCV 代码转换为 C# Emgucv。我转换了一些行,但我卡在了一行上。

Mat detectionMat(detection.size[2], detection.size[3], CV_32F, detection.ptr<float>());

我像上面那样转换了

 Mat detectionMat = new Mat(detection.SizeOfDimemsion[2], detection.SizeOfDimemsion[3], Emgu.CV.CvEnum.DepthType.Cv32F, detection.Ptr.ToPointer());

但我知道 detection.Ptr.ToPointer() 有问题,我无法转换。提前致谢。

 caffe.PopulateNet(net);

        Mat prob;
        Mat img2 = new Mat(300,300,img.Depth,img.NumberOfChannels); 
        Emgu.CV.CvInvoke.Resize(img, img2, new Size(300, 300));

        //Mat inputBlob = DnnInvoke.BlobFromImage(img2,0.007843, new Size(300, 300), new MCvScalar(127.5,127.5,127.5), true); // ??
        Mat inputBlob = DnnInvoke.BlobFromImage(img, 0.007843, mean: new MCvScalar(127.5, 127.5, 127.5), swapRB: false); 
        net.SetInput(inputBlob, "data");

        Mat detection = net.Forward("detection_out");
        Mat detectionMat = new Mat(detection.SizeOfDimemsion[2], detection.SizeOfDimemsion[3], Emgu.CV.CvEnum.DepthType.Cv32F, detection.ptr<float>()); 

        double confidenceThreshold = 0.2;

【问题讨论】:

    标签: c# c++ opencv image-processing emgucv


    【解决方案1】:

    @Musa,您使用的是哪个版本的 Emgu CV。在最新版本中,没有采用您指定的参数的 Mat 构造函数。您可以选择:

    Mat Constructor (Int32, Int32, DepthType, Int32)
    Mat Constructor (Int32[], DepthType, IntPtr,IntPtr[])
    Mat Constructor (Size, DepthType, Int32, IntPtr, Int32)
    Mat Constructor (Int32, Int32, DepthType, Int32, IntPtr, Int32)
    

    我猜你的意思是使用最后一个。如果是这样,这是您数据的 IntPtr。但不知道数据是什么我帮不上什么忙。了解什么是检测或完整的代码 sn-p 将非常有帮助。

    编辑: Musa,我想我明白你在做什么,尽管我没有使用 EmguCV 的 DNN 部分。作为 net.Forward() 调用的结果,您有一个 Mat 对象。我认为您可以尝试以下方法,看看是否有帮助:

    Mat detectionMat = new Mat(detection.SizeOfDimemsion[2], detection.SizeOfDimemsion[3], Emgu.CV.CvEnum.DepthType.Cv32F, detection.NumberOfChannels, detection.DataPointer, detection.Step);
    

    道格

    【讨论】:

    • 感谢回复,我使用的是 3.3.0 EmguCV 版本。我还将使用所有代码行编辑问题。感谢关注
    • 我会在我也告知最后一站之后。感谢您的关注
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-26
    相关资源
    最近更新 更多