如何获取文本中每个单词的边界矩形(用于阅读眼球跟踪)?

时间:2015-07-12 04:16:00

标签: matlab psychtoolbox

对于眼动追踪研究,我需要在窗口中绘制的文本中每个单词的位置。 我可以看到如何使用

将整个文本的边界框作为返回值
[nx, ny, textbounds] = DrawFormattedText(win, tstring)

有没有比使用这个功能逐字逐句绘制整个句子更好的方法?

1 个答案:

答案 0 :(得分:0)

这样的事情应该这样做:

teststr = {'Hello World!' ; 'How are you doing?'}

ystart = 100
xstart = 200
wordgap = 10

for i=1:size(teststr,1)

  str=teststr{i};
  wordlist = strsplit(str , ' ');

  for j=1:size(wordlist)(1)
    [nx, ny, textbounds]=DrawFormattedText(win, wordlist{j} ,xstart, ystart);
    poslist{j} = textbounds;
    xstart=nx+wordgap;
  end

end

不漂亮,但它有效。如果你有换行符,你会遇到问题。

编辑:2015-07-14:从sven.io

添加了wordgap建议
相关问题