我尝试实现一种用种子点分割图像的方法,并将每个像素分配给最近的点。
例如,如果像素接近1,则设置为1。
输入:
0 0 0 0 0 3 0
0 1 0 0 0 0 0
0 0 0 0 2 0 0
0 0 0 0 0 0 0
Run Code Online (Sandbox Code Playgroud)
输出:
1 1 1 3 3 3 3
1 1 1 2 2 3 3
1 1 1 2 2 2 2
1 1 1 2 2 2 2
Run Code Online (Sandbox Code Playgroud)
目前的方法需要太长的时间并计算(width * height * numPoints)次,有没有任何算法可以更快?
7秒处理5 9478 * 1868张图像,numPoints = 8
for (int i = 0; i < height; i++) …Run Code Online (Sandbox Code Playgroud) 这是某家公司的测试。
重载 & 返回 int[][] 的总和
main()
{
int arr[5][5];
// initialization
cout << &arr; // output the sum of arr
}
Run Code Online (Sandbox Code Playgroud)
我尝试此代码但返回编译错误:
long operator &(int** arr)
{
// return the sum of arr
}
Run Code Online (Sandbox Code Playgroud)
错误:参数应该包含类类型或枚举目前我理解这个错误,但是如何为内置类型重载运算符?