我试图使用NumPy获取与特定颜色不同的图像像素列表.
例如,在处理以下图像时:
我设法使用以下方法获取所有黑色像素的列表:
np.where(np.all(mask == [0,0,0], axis=-1))
Run Code Online (Sandbox Code Playgroud)
但是当我尝试做的时候:
np.where(np.all(mask != [0,0,0], axis=-1))
Run Code Online (Sandbox Code Playgroud)
我得到一个非常奇怪的结果:
看起来NumPy只返回了指数,R,G和B都是非0
这是我正在尝试做的最小例子:
import numpy as np
import cv2
# Read mask
mask = cv2.imread("path/to/img")
excluded_color = [0,0,0]
# Try to get indices of pixel with different colors
indices_list = np.where(np.all(mask != excluded_color, axis=-1))
# For some reason, the list doesn't contain all different colors
print("excluded indices are", indices_list)
# Visualization
mask[indices_list] = [255,255,255]
cv2.imshow(mask)
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud) 假设我有一系列课程:
class Port8Bit{
void Write(uint8_t data);
uint8_t Read();
};
class Port16Bit{
void Write(uint16_t data);
uint16_t Read();
};
//and so on for 32Bit and 64Bit
Run Code Online (Sandbox Code Playgroud)
当我想启动类,而不是为每个类再次编写代码时,我可以使用一个宏:
#define intiatePort(portSize) { \
Port##portSize##Bit::Port##portSize##Bit(){ \
} \
\
void Port##portSize##Bit::Write(uint##portSize##_t data){ \
\ //write data
} \
uint##portSize##_t Port##portSize##Bit::Read(){ \
uint##portSize##_t result; \
\ //read data
return result; \
}
Run Code Online (Sandbox Code Playgroud)
我对CPP很新,但我读过在大多数情况下使用宏并不是一个好习惯.我想知道,有更好的,更多的CPP方式吗?
有没有办法检查我的Android应用程序是否正在调试,如DEBUG标志或somthing?我想在调试应用程序时打印一条特殊消息.