由于某些未知原因,Pyautogui的 import Foundation
import Metal
import UIKit
class MetalShit :NSObject{
var myGPU : MTLDevice!
var mLayer : CAMetalLayer!
// must copied from destination view
var view : UIView!
var pipelineState : MTLRenderPipelineState!
var commandQueue : MTLCommandQueue!
var timer : CADisplayLink!
convenience init(view: UIView) {
self.init()
self.view = view
}
func renderthem() {
myGPU = MTLCreateSystemDefaultDevice()
mLayer = CAMetalLayer()
mLayer.device = myGPU
mLayer.pixelFormat = .bgra8Unorm
mLayer.framebufferOnly = true
mLayer.frame = view.frame
view.layer.addSublayer(mLayer)
// setup once
let vertexData : [Float] = [0.5,1.0,0.0,
-1.0,-1.0,0.0,
1.0,-1.0,0.0]
var vertexBuffer : MTLBuffer!
let datasize = vertexData.count * MemoryLayout.size(ofValue: vertexData[0])
vertexBuffer = myGPU.makeBuffer(bytes: vertexData, length: datasize, options: [])
let defaultLibrary = myGPU.makeDefaultLibrary()
let fragmentProgram = defaultLibrary?.makeFunction(name: "noobFragment")
let vertexProgram = defaultLibrary?.makeFunction(name: "noobShader")
let pipelineDes = MTLRenderPipelineDescriptor()
pipelineDes.vertexFunction = vertexProgram
pipelineDes.fragmentFunction = fragmentProgram
pipelineDes.colorAttachments[0].pixelFormat = .bgra8Unorm
pipelineState = try! myGPU.makeRenderPipelineState(descriptor: pipelineDes)
commandQueue = myGPU.makeCommandQueue()
// render things
timer = CADisplayLink(target: self, selector: #selector(gameLoop))
timer.add(to: RunLoop.main, forMode: RunLoopMode.defaultRunLoopMode)
guard let drawable = mLayer?.nextDrawable() else {return}
let renderPassDes = MTLRenderPassDescriptor()
renderPassDes.colorAttachments[0].texture = drawable.texture
renderPassDes.colorAttachments[0].loadAction = .clear
renderPassDes.colorAttachments[0].clearColor = MTLClearColor(red: 0.0, green: 104.0/255.0, blue: 5.0/255.0, alpha: 0.5)
let commandBuffer = commandQueue.makeCommandBuffer()
let renderEncoder = commandBuffer?.makeRenderCommandEncoder(descriptor: renderPassDes)
renderEncoder?.setRenderPipelineState(pipelineState)
renderEncoder?.setVertexBuffer(vertexBuffer, offset: 0, index: 0)
renderEncoder?.drawPrimitives(type: .triangle , vertexStart: 0, vertexCount: 3, instanceCount: 1)
renderEncoder?.endEncoding()
commandBuffer?.present(drawable)
commandBuffer?.commit()
// encoders
}
@objc func gameLoop(){
}
func render (){
}
}
函数(以及所有其他Pyautogui的locate函数)无法正常工作并返回locateOnScreen()
。
我的代码:
None
我的研究
我知道,当它返回>>> pyautogui.screenshot('test.png',region=(100,20, 30, 20))
<PIL.Image.Image image mode=RGB size=30x20 at 0x39E35C0>
>>> print pyautogui.locateOnScreen('test.png')
None
时,这意味着None
无法找到在屏幕上的图像。我也知道它必须在屏幕上可见。上面的代码是在不移动单个窗口时执行的。
我也知道在stackoverflow上有非常相似/相同的问题,例如this one。但是该问题的解决方案不适用于我的情况,因为我实际上是直接使用 pyautogui的屏幕截图和裁剪功能,甚至没有使用3rd party软件进行裁剪,但是pyautogui无法找到它。 / p>
其他信息
Python:pyautogui
操作系统:2.7.15 (64-bit)
答案 0 :(得分:0)
locateOnScreen
,locateCenterOnScreen
和(可能)所有其他Pyautogui的 locate 函数都有一个可选参数confidence
。
顾名思义,设置Pyautogui可以容忍轻微偏差的程度。降低置信度值可以解决此问题,但会增加误报的可能性。
旁注:Pyautogui's documentation中未提及confidence
。如果他们可以在其中添加它,那将是非常不错的帮助。