![](/img/trans.png)
[英]CSS, How do I set the min-height/width to the screen height/width only on first page load?
[英]How do I find a specific color and ask the position, width and height of it
大家好。
例如,是否可以在Photoshop中創建圖片並在其中制作黑色表面,以便Unity可以找到特定的黑色表面並從中請求其位置,寬度和高度。
我想讓我的應用程序自動運行。 我的意思是,如果人們制作的360天幕上有幾個黑色區域,我可以在代碼中說Unity必須找到這些黑色區域,然后在其中放電影。
誰能幫我?
如果我理解正確,您想要獲得具體顏色和寬度和高度的位置。 我之前用aspose做過,模板是我的代碼,希望對您有所幫助
public static void CheckRotation(string imageFilePath, string templateFilePath, int tryCount)
{
if (tryCount > 2)
throw new Exception("the Image Cant be Detected");
int leftTotal = 0;
int leftBlackColor = 0;
int rightTotal = 0;
int rightBlackColor = 0;
byte findLeftAndRight = 0;
OmrTemplate template = OmrTemplate.Load(templateFilePath);
OmrImage image = OmrImage.Load(imageFilePath);
OmrEngine engine = new OmrEngine(template);
image.AutoDetectResolution = true;
OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image });
Hashtable OmrResult = result.PageData[0];
ICollection key = OmrResult.Keys;
OmrElementsCollection collection = template.Pages[0].Elements;
foreach (Object obj in collection)
{
if (obj.GetType() == typeof(ChoiceBoxElement))
{
var elem = (ChoiceBoxElement)obj;
if (elem.Name.ToString().ToUpper() == "LEFT" || elem.Name.ToString().ToUpper() == "RIGHT")
{
findLeftAndRight++;
var xPosition = int.Parse(Math.Floor((elem.Position.X * 150) / 25.4).ToString()) + 1;
var yPosition = int.Parse(Math.Floor((elem.Position.Y * 150) / 25.4).ToString()) + 1;
Bitmap bitmap = new Bitmap(imageFilePath);
BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(xPosition, yPosition, int.Parse(Math.Floor((elem.Size.Width * 150) / 25.4).ToString()), int.Parse(Math.Floor((elem.Size.Height * 150) / 25.4).ToString())),
ImageLockMode.ReadOnly, bitmap.PixelFormat); // make sure you check the pixel format as you will be looking directly at memory
unsafe
{
// example assumes 24bpp image. You need to verify your pixel depth
// loop by row for better data locality
for (int y = 0; y < data.Height; ++y)
{
byte* pRow = (byte*)data.Scan0 + y * data.Stride;
for (int x = 0; x < data.Width; ++x)
{
// windows stores images in BGR pixel order
byte r = pRow[2];
byte g = pRow[1];
byte b = pRow[0];
if (elem.Name.ToString().ToUpper() == "LEFT")
leftTotal++;
else if (elem.Name.ToString().ToUpper() == "RIGHT")
rightTotal++;
if (
(r == 0 && g == 0 && b == 0) ||
((r < 100 && g < 100) || (r < 100 && b < 100) || (b < 100 && g < 100)) ||
(r < 120 && g < 120 && b < 120 && Math.Abs(r - g) < 10 && Math.Abs(r - b) < 10 && Math.Abs(b - g) < 10)
)
{
if (elem.Name.ToString().ToUpper() == "LEFT")
leftBlackColor++;
else if (elem.Name.ToString().ToUpper() == "RIGHT")
rightBlackColor++;
}
// next pixel in the row
pRow += 3;
}
}
}
bitmap.UnlockBits(data);
}
}
}
if (findLeftAndRight != 2)
throw new Exception("The Left and Right Mark Didnt Exists!!");
var leftPercentage = (leftBlackColor / leftTotal) * 100;
var rightPercentage = (rightBlackColor / rightTotal) * 100;
if (leftPercentage > 80 && rightPercentage > 80) //It means The Paper is Currect Rotation
return;
else
{
RotateImage(imageFilePath, 180);
CheckRotation(imageFilePath, templateFilePath, ++tryCount);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.