小编tih*_*rbz的帖子

JTable 添加 File 对象,但只显示 File Name

我有一个 Java 应用程序,它使用 JTables 添加文件以供浏览。它仅包含 1 列:

DefaultTableModel model = new DefaultTableModel(new String[] {"Name"}, 0);

    JTable tracks = new JTable(model){
        public boolean isCellEditable(int rowIndex, int collIndex){
            return false;
        }
    };

tracks.addMouseListener(new PopupListener());

tracks.setShowGrid(false);
Run Code Online (Sandbox Code Playgroud)

将文件添加到表是这样完成的:

for (File file : results){
    model.addRow(new Object[] {file});
}
Run Code Online (Sandbox Code Playgroud)

我需要添加实际文件,而不仅仅是它的名称,因为我稍后会使用它。但是,该表是否可能只显示文件名(file.getName();)而不是整个路径?

java swing file jtable defaulttablemodel

2
推荐指数
1
解决办法
601
查看次数

具有多个条件的Python numpy数组迭代图像

我正在过滤一些图像以删除不必要的背景,到目前为止,检查像素BGR(使用openCV)值已取得最大成功.问题是用2个嵌套循环迭代图像太慢了:

h, w, channels = img.shape
    for x in xrange(0,h):
        for y in xrange (0,w):
            pixel = img[x,y]
            blue = pixel[0]
            green = pixel[1]
            red = pixel[2]

            if green > 110:
                img[x,y] = [0,0,0]
                continue

            if blue < 100 and red < 50 and green > 80:
                img[x,y] = [0,0,0]
                continue
Run Code Online (Sandbox Code Playgroud)

还有一些类似的if语句,但你明白了.问题是在i7上的672x1250上大约需要10秒钟.

现在,我可以轻松地执行第一个if语句,如下所示:

img[np.where((img > [0,110,0]).all(axis=2))] = [0,0,0]
Run Code Online (Sandbox Code Playgroud)

并且速度要快得多,但我似乎无法使用np.where来执行其他具有多个条件的if语句.

这是我尝试过的:

img[np.where((img < [100,0,0]).all(axis=2)) & ((img < [0,0,50]).all(axis=2)) & ((img > [0,80,0]).all(axis=2))] = [0,0,0]
Run Code Online (Sandbox Code Playgroud)

但抛出一个错误:

ValueError: operands could not be broadcast …
Run Code Online (Sandbox Code Playgroud)

python arrays opencv numpy

2
推荐指数
1
解决办法
1004
查看次数

标签 统计

arrays ×1

defaulttablemodel ×1

file ×1

java ×1

jtable ×1

numpy ×1

opencv ×1

python ×1

swing ×1