- Home /
cannot convert `System.Drawing.Size' expression to type `System.Drawing.Size'?
I'm working with emgu in unity. I'm trying to test CascadeClassifier for face detection. I want to call DetectMultiScale from the CascadeClassifier class, which is defined as:
/// </summary>
/// <param name="image">The image where the objects are to be detected from</param>
/// <param name="scaleFactor">The factor by which the search window is scaled between the subsequent scans, for example, 1.1 means increasing window by 10%</param>
/// <param name="minNeighbors">Minimum number (minus 1) of neighbor rectangles that makes up an object. All the groups of a smaller number of rectangles than min_neighbors-1 are rejected. If min_neighbors is 0, the function does not any grouping at all and returns all the detected candidate rectangles, which may be useful if the user wants to apply a customized grouping procedure. Use 3 for default.</param>
/// <param name="minSize">Minimum window size. Use Size.Empty for default, where it is set to the size of samples the classifier has been trained on (~20x20 for face detection)</param>
/// <param name="maxSize">Maxumum window size. Use Size.Empty for default, where the parameter will be ignored.</param>
/// <returns>The objects detected, one array per channel</returns>
public Rectangle[] DetectMultiScale(IInputArray image, double scaleFactor = 1.1, int minNeighbors = 3, Size minSize = new Size(), Size maxSize = new Size())
{
using (Util.VectorOfRect rectangles = new Util.VectorOfRect())
{
CvCascadeClassifierDetectMultiScale(_ptr, image.InputArrayPtr, rectangles, scaleFactor, minNeighbors, 0, ref minSize, ref maxSize);
return rectangles.ToArray();
}
}
The call in my code is as:
Image<Bgr, byte> picture = new Image<Bgr, byte>("lena.jpg");
Image<Gray, byte> img_gray = image.Convert<Gray, byte>();
CascadeClassifier haar = new CascadeClassifier("haarcascade_frontalface_default.xml");
Rectangle[] face = haar.DetectMultiScale( img_gray, 1.1, 10, Size.Empty, Size.Empty);
But I'm getting errors:
error CS1502: The best overloaded method match for
Emgu.CV.CascadeClassifier.DetectMultiScale(Emgu.CV.IInputArray, double, int, System.Drawing.Size, System.Drawing.Size)' has some invalid arguments > error CS1503: Argument
#4' cannot convertSystem.Drawing.Size' expression to type
System.Drawing.Size'
Can anyone help?
Answer by tanoshimi · May 27, 2014 at 07:29 PM
Unity doesn't support classes from the System.Drawing namespace.
Possible workaround: http://answers.unity3d.com/questions/53170/using-drawing-package-like-systemdrawing.html
Ok. I have already done the workaround in your link, and have done other simple examples with emgu that instructed me to do that to see if it worked and they were ok. But since I didn't have any other ideas I went and recopy System.Drawing.dll from %UnityFolder%\Editor\Data\$$anonymous$$ono\lib\mono\2.0 to my plugins folder and now is working! I not sure were I have gotten the System.Drawing.dll file that was before I copy the one on %UnityFolder%\Editor\Data\$$anonymous$$ono\lib\mono\2.0. Could the problem have been there?? Anyway thanks a lot. I try to vote up your answer but it doesn't let me.
Your answer
![](https://koobas.hobune.stream/wayback/20220613150018im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Cloud recognition in Vuforia 0 Answers
Sign Apk In Unity3d For Google Player Store 0 Answers
How do I export blender tree model into Unity3D? 2 Answers
Read a sound in unity 3D triggered from an iPad 1 Answer
Load a Level on Touch 1 Answer