- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想自动化将棋盘图像的方 block 分类为黑色或白色方 block 的过程。进一步的步骤是区分它是一个空方 block 还是包含一个方 block 。到目前为止,我接近于使用正方形中心的平均强度将每个正方形分类为白色或黑色,但很难设置阈值。对于更进一步的步骤(空方 block 或一 block ),我尝试使用 std2
但也很困难。
这是我的脚本:
image = imerode(original,strel('disk',3));
image = imadjust(image,[],[],2);
figure,imshow(image),hold on;
for i = 1:length(cells)
TL = cells(i).TL; %Cell's corner top left
TR = cells(i).TR; %Cell's corner top right
BL = cells(i).BL; %Cell's corner bottom left
BR = cells(i).BR; %Cell's corner bottom right
x = [TL(1) TR(1) BR(1) BL(1)];
y = [TL(2) TR(2) BR(2) BL(2)];
bw = poly2mask(x,y,size(image,1),size(image,2));
measurements = regionprops(bw,'BoundingBox');
cropped = imcrop(image, measurements.BoundingBox);
m = regionprops(bw,'Centroid');
x = m.Centroid(1);
y = m.Centroid(2);
w = 25; %width
h = 25; %height
tl = [round(x-w/2) round(y-h/2)];
center = image(tl(1):tl(1)+w,tl(2):tl(2)+h,:);
%stds(i) = std2(center);
avgs(i) = mean2(center);
if(avgs(i) > 55)
str = "W";
else
str = "B";
end
text(x,y,str,'Color','red','FontSize',16);
end
编辑:下图是
之后的新结果image = imerode(image,strel('disk',4));
image = image>160;
最佳答案
您可以使用 Matlabs 内置的棋盘方法 detectCheckerboardPoints
和 checkerboard
来查找棋盘的大小并构建一个合适大小的新棋盘。由于只能存在两种可能的棋盘,因此构建两者并检查哪一个匹配最好。
img = imread('PNWSv.jpg'); %Load image
%Prepare image
I = rgb2gray(img);
I2 = imerode(I,strel('square',10));
bw = imbinarize(I2,'adaptive');
%Find checkerboard points
[imagePoints,boardSize] = detectCheckerboardPoints(bw);
%Find the size of the checkerboard fields
x = boardSize(2)-1;
y = boardSize(1)-1;
fields = cell(y,x);
for k = 1:length(imagePoints)
[i,j] = ind2sub([y,x],k);
fields{i,j} = imagePoints(k,:);
end
avgDx = mean(mean(diff(cellfun(@(x) x(1),fields),1,2)));
avgDy = mean(mean(diff(cellfun(@(x) x(2),fields),1,1)));
%Construct the two possibilities
ref1 = imresize(imbinarize(checkerboard),[avgDx,avgDy]*8);
ref2 = imcomplement(ref1);
%Check which ones fits the better
c1 = normxcorr2(ref1,I);
c2 = normxcorr2(ref2,I);
if max(c2(:))<max(c1(:))
ref=ref1;
c = c1;
else
ref=ref2;
c = c2;
end
%Plot the checkerboard bounding box on top of the original image
[ypeak, xpeak] = find(c==max(c(:)));
yoffSet = ypeak-size(ref,1);
xoffSet = xpeak-size(ref,2);
imshow(img);
imrect(gca, [xoffSet+1, yoffSet+1, size(ref1,2), size(ref1,1)]);
关于matlab - 如何区分黑棋盘格和白棋盘格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48863940/
我有一个棋盘格,并将其连接到 JPanel: import javax.swing.*; import java.awt.Graphics; import java.awt.Color; public
我看不出有什么问题,我正在尝试将 gameBoard 数组(这不是数组吗?- 请参阅构造函数)传递到 findPiece 方法中,但它说了不是一个数组,我应该在这里传递什么来获得未更新的板?抱歉,我是
所以我想检查输入的位置在棋盘中是否有效, //returns true if the position is in the range of A1-H8 private boolean isValid
将单一职责原则应用于棋盘应用程序,Piece 接口(interface)/类应该负责什么? 我确信它需要知道它的颜色、类型和有效 Action 。但是它是否也应该知道它在棋盘中的位置(x/y)?或者,
我需要使用 J 打印棋盘,给定奇数的函数需要创建一个 NxN 矩阵并在每个其他框中放置一个“X”。我已经制作了矩阵,但我无法弄清楚其他盒子部分。 到目前为止我所拥有的 N =: 3 checker =
我目前有一个一维棋盘坐标数组(例如 ["B1","D1","F1","H1","E8"] 用于棋盘游戏。我已将数组“位置”初始化为是上面的值,但这可以是游戏任何时候的任何值。该数组的长度根据用户给定的
我想使用canvas和通过覆盖方法onDraw在android studio中动态绘制一个8×8的棋盘,我几乎已经成功了,但我遇到了一个非常烦人的问题。 我已经制作了一个自定义 View ,我的目标是
所以我开始了一个 TicTacToe 项目,而且我是一个初学者,所以我不知道如何做很多事情。这是半个小时编码的结果。 我似乎在调试 Player2 不轮流的原因时遇到问题。 所以它要求添加更多细节,然
我正在制作棋盘游戏,但无法 move 它们。棋子会根据骰子的结果 move 。下面是我尝试做的,但它不起作用。(来自 button[].addActionListener(new ActionList
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找书籍、工具、软件库、教程或其他场外资源的问题对于 Stack Overflow 来说是
谁能告诉我如何使用 JavaScript、表格标签或 生成棋盘 (8x8)? 到目前为止,我得到了以下内容: div { border:1px solid black; width:20px;
大家好,我最近开始做一个国际象棋应用程序,除了 GUI 之外,我已经设置好了所有的东西。出于某种原因,我无法让电路板显示瓷砖,我也不知道为什么。 (推测)我认为我的问题与我对 DOM 的使用有关。对我
我试图创建一个带有表格的棋盘 (HTML/CSS)。我在表格边框方面遇到了麻烦。我只希望电路板有边框,排除行号和列字母。 我该怎么做? table { border-bottom: solid 2
我是 java 和 android 的新手,但我正在寻找一个可以走上正轨的好教程。我想编写一个函数,用于在我的应用程序当前 View 的背景中绘制/重绘白底黑棋盘图案。我不想使用实际图像,因为我希望能
我正在尝试使用 GUI 的 NetBeans IDE 在 Java 中制作国际象棋游戏,但我无法使棋子停留在棋盘上方,当我尝试时,棋盘就会被推开。我对这两个图像都使用了标签。如何让棋子停留在棋盘上方而
我试图为 Tic Tac Toe 游戏编写代码。我编写了以下代码来显示游戏板,但出现了问题,并且没有显示所需的输出。你能帮我找出错误在哪里吗? 这里: 0代表空白, 1代表X和 2代表O。 publi
我的任务是通过 paintComponent 方法创建一个 10x10 可调整大小的棋盘。 我的问题是第一行正确,但下一行不显示,我根本不知道我的错误在哪里 GrafikPanel 类: import
我在这里尝试使用 javascript 棋盘:http://chessboardjs.com/ .不幸的是,我不知道 javascript 或 CSS,并且对 HTML 很生疏,所以我不理解文档,即使
我正在尝试在棋盘(见附图)和基于 cordova 的 Android 国际象棋游戏(lichess)之间传输数据。两个设备都将通过 USB 数据线连接。 android 的 cordova 应用程序是
我使用以下 CSS 代码创建了一个棋盘图案: .testcheckerboard{ width: 200px; height: 100px; background-color: white
我是一名优秀的程序员,十分优秀!