【发布时间】:2018-06-28 06:43:24
【问题描述】:
例如:用户选择 1000 * 1000 图像我发送到后端以检测对象,因此我正在获取图像中存在的对象的坐标。
Like this :(
{
x = 385;
y = 249;
},
{
x = 448;
y = 242;
},
{
x = 454;
y = 276;
},
{
x = 391;
y = 284;
}
);
我将图像视图设置为宽高比,因此图像的实际大小会有所不同,因此我需要根据宽高比匹配大小更改坐标以适应宽高比匹配大小的图像。
这是我尝试过的代码。
var topLeftXOne = point[0]["x"] as! CGFloat
var topLeftYOne = point[0]["y"] as! CGFloat
var topRightXOne = point[1]["x"] as! CGFloat
var topRightYOne = point[1]["y"] as! CGFloat
var bottomtopRightXOne = point[2]["x"] as! CGFloat
var bottomRightYOne = point[2]["y"] as! CGFloat
var bottomLeftXOne = point[3]["x"] as! CGFloat
var bottomLeftYOne = point[3]["y"] as! CGFloat
let pointsView = ALPDView(frame: CGRect.zero)
let x: CGRect = AVMakeRect(aspectRatio: image.size, insideRect: pointsView.imageView.frame)
let scaleX = image.size.width / x.width
let scaleY = image.size.height / x.height
topLeftXOne = topLeftXOne / scaleX
topLeftYOne = topLeftYOne / scaleY
topRightXOne = topRightXOne / scaleX
topRightYOne = topRightYOne / scaleY
bottomtopRightXOne = bottomtopRightXOne / scaleX
bottomRightYOne = bottomRightYOne / scaleY
bottomLeftXOne = bottomLeftXOne / scaleX
bottomLeftYOne = bottomLeftYOne / scaleY
但我没有得到正确的结果。
这个例如image ,我想更改坐标以适应宽高比图像大小。
【问题讨论】:
标签: ios swift uiimage uibezierpath cgpoint