这是我的整个代码。我在这里做的是试图找到图像和我从图像中减去的模板之间的匹配点。如何在Matlab中对不同图像中的对象数进行求和?
第一个循环和第二个循环从原始图像中提取所有卡片(第一张图像与一组卡片) 代码的下一部分是找到提取的卡片和模板之间的匹配点。 (selectCard) 然后我创建了for循环(selectCard),并且我将连接的组件应用到了当他们通过选择标准时,对卡上剩余的物体进行计数。
所以我需要获得所有通过我所做选择标准的牌的总数。基本上,我得到了每张牌的结果。不是所有的卡。我需要计算所有这些卡的结果。
for j=1:max(max(LabeledImage))
[row, col] = find(LabeledImage==j);
len=max(row)-min(row)+2;
breadth=max(col)-min(col)+2;
Img=uint8(zeros([len breadth 3]));
sy=min(col)-1;
sx=min(row)-1;
for i=1:size(row,1)
x=row(i,1)-sx;
y=col(i,1)-sy;
Img(x,y,:)=grayImage(row(i,1),col(i,1),:);
end
mytitle=strcat('Card Number:',num2str(j));
% figure,imshow(Img);title(mytitle);
Img=rgb2gray(Img);
pointsForSpade1 = detectHarrisFeatures(Img);
pointsForSpade2 = detectHarrisFeatures(Template_for_spade);
%extract neighborhood features
[featuresForSpade1,valid_pointsForSpade1] =
extractFeatures(Img,pointsForSpade1);
[featuresForSpade2,valid_pointsForSpade2] =
extractFeatures(Template_for_spade,pointsForSpade2);
%Match the features
indexPairs = matchFeatures(featuresForSpade1,featuresForSpade2);
%retrieve the locations of the corresponding points for each image.
matchedPointsForSpade1 = valid_pointsForSpade1(indexPairs(:,1),:);
matchedPointsForSpade2 = valid_pointsForSpade2(indexPairs(:,2),:);
% visualize the corresponding points.
figure,subplot(5,5,j)
showMatchedFeatures(Img,Template_for_spade,matchedPointsForSpade1,.....
matchedPointsForSpade2, 'montage');
count1 = matchedPointsForSpade1.Count;
%disp(matchedPoints1);
selectCard4 = find(count1>10);
Total = 0;
for e4= 1: selectCard4
figure, subplot(5,5,j)
showMatchedFeatures(Img(e4),Template_for_spade,matchedPointsForSpade1,...
matchedPointsForSpade2, 'montage');
title(Name);
% eliminate not needed hole on the card.
level = 0.57;
Img2 = imbinarize(Img, level);
%Morphological operation
ImgComp = imcomplement(Img2);
se = strel('disk', 10);
Iopened = imopen(ImgComp, se);
%figure;
%imshow(Iopened);
[Label3, numObject4] = bwlabel(Iopened);
TotalSpade = sum(numObject4);
s = sprintf('\n card number: of this set has #%s spades',j,
num2str(TotalSpade));
disp(s);
end
end
我想根据选定的卡显示连接对象的总和。
谢谢。
请发表[mcve]。 'bwlabel'将返回找到的组件的数量,所以这只是对这两个数字求和的问题。 – beaker
谢谢。我编辑过,以防你仍然想要帮助! – steve
@steve你的代码只是一遍又一遍地找到同一个图像'Iopened'的连接组件,'sum'没有做任何事情,但它看起来应该为该图像打印正确数量的组件。你想要你的代码做什么不同?另外,如果你正在回应某人,你应该像@beaker那样对他们进行ping,以便他们得到通知。否则,他们不知道你已经回复了他们(一般来说......有例外)。 – beaker