mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-25 12:28:14 +08:00
Opt: [ALAS] Reuse image array to improve memory performance
This commit is contained in:
@@ -128,7 +128,7 @@ class Adb(Connection):
|
|||||||
if image is None:
|
if image is None:
|
||||||
raise ImageTruncated('Empty image after cv2.imdecode')
|
raise ImageTruncated('Empty image after cv2.imdecode')
|
||||||
|
|
||||||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
cv2.cvtColor(image, cv2.COLOR_BGR2RGB, dst=image)
|
||||||
if image is None:
|
if image is None:
|
||||||
raise ImageTruncated('Empty image after cv2.cvtColor')
|
raise ImageTruncated('Empty image after cv2.cvtColor')
|
||||||
|
|
||||||
|
|||||||
@@ -165,11 +165,11 @@ class AScreenCap(Connection):
|
|||||||
# ValueError: cannot reshape array of size 0 into shape (720,1280,4)
|
# ValueError: cannot reshape array of size 0 into shape (720,1280,4)
|
||||||
raise ImageTruncated(str(e))
|
raise ImageTruncated(str(e))
|
||||||
|
|
||||||
image = cv2.flip(image, 0)
|
cv2.flip(image, 0, dst=image)
|
||||||
if image is None:
|
if image is None:
|
||||||
raise ImageTruncated('Empty image after cv2.flip')
|
raise ImageTruncated('Empty image after cv2.flip')
|
||||||
|
|
||||||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
cv2.cvtColor(image, cv2.COLOR_BGR2RGB, dst=image)
|
||||||
if image is None:
|
if image is None:
|
||||||
raise ImageTruncated('Empty image after cv2.cvtColor')
|
raise ImageTruncated('Empty image after cv2.cvtColor')
|
||||||
|
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ class DroidCast(Uiautomator2):
|
|||||||
if image is None:
|
if image is None:
|
||||||
raise ImageTruncated('Empty image after cv2.imdecode')
|
raise ImageTruncated('Empty image after cv2.imdecode')
|
||||||
|
|
||||||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
cv2.cvtColor(image, cv2.COLOR_BGR2RGB, dst=image)
|
||||||
if image is None:
|
if image is None:
|
||||||
raise ImageTruncated('Empty image after cv2.cvtColor')
|
raise ImageTruncated('Empty image after cv2.cvtColor')
|
||||||
|
|
||||||
@@ -211,14 +211,25 @@ class DroidCast(Uiautomator2):
|
|||||||
# image = cv2.merge([r, g, b])
|
# image = cv2.merge([r, g, b])
|
||||||
|
|
||||||
# The same as the code above but costs about 5ms instead of 10ms.
|
# The same as the code above but costs about 5ms instead of 10ms.
|
||||||
r = cv2.multiply(arr & 0b1111100000000000, 0.00390625).astype(np.uint8)
|
r = cv2.bitwise_and(arr, 0b1111100000000000)
|
||||||
g = cv2.multiply(arr & 0b0000011111100000, 0.125).astype(np.uint8)
|
cv2.multiply(r, 0.00390625, dst=r)
|
||||||
b = cv2.multiply(arr & 0b0000000000011111, 8).astype(np.uint8)
|
r = np.uint8(r)
|
||||||
r = cv2.add(r, cv2.multiply(r, 0.03125))
|
m = cv2.multiply(r, 0.03125)
|
||||||
g = cv2.add(g, cv2.multiply(g, 0.015625))
|
cv2.add(r, m, dst=r)
|
||||||
b = cv2.add(b, cv2.multiply(b, 0.03125))
|
|
||||||
image = cv2.merge([r, g, b])
|
|
||||||
|
|
||||||
|
g = cv2.bitwise_and(arr, 0b0000011111100000)
|
||||||
|
cv2.multiply(g, 0.125, dst=g)
|
||||||
|
g = np.uint8(g)
|
||||||
|
m = cv2.multiply(g, 0.015625)
|
||||||
|
cv2.add(g, m, dst=g)
|
||||||
|
|
||||||
|
b = cv2.bitwise_and(arr, 0b0000000000011111)
|
||||||
|
cv2.multiply(b, 8, dst=b)
|
||||||
|
b = np.uint8(b)
|
||||||
|
m = cv2.multiply(b, 0.03125)
|
||||||
|
cv2.add(b, m, dst=b)
|
||||||
|
|
||||||
|
image = cv2.merge([r, g, b])
|
||||||
return image
|
return image
|
||||||
|
|
||||||
def droidcast_wait_startup(self):
|
def droidcast_wait_startup(self):
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ class Uiautomator2(Connection):
|
|||||||
if image is None:
|
if image is None:
|
||||||
raise ImageTruncated('Empty image after cv2.imdecode')
|
raise ImageTruncated('Empty image after cv2.imdecode')
|
||||||
|
|
||||||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
cv2.cvtColor(image, cv2.COLOR_BGR2RGB, dst=image)
|
||||||
if image is None:
|
if image is None:
|
||||||
raise ImageTruncated('Empty image after cv2.cvtColor')
|
raise ImageTruncated('Empty image after cv2.cvtColor')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user