我有这样的代码
BigDecimal withoutTax, tax, withTax, totalPrice;
totalPrice = new BigDecimal(0.0);
BigDecimal amount = new BigDecimal(String.valueOf(table.getValueAt(table.getSelectedRow(), 3)).replace(",", "."));
BigDecimal price = new BigDecimal(String.valueOf(table.getValueAt(table.getSelectedRow(), 4)).replace(",", "."));
withoutTax = amount.multiply(price, new MathContext(5));
table.setValueAt(withoutTax.toPlainString(), table.getSelectedRow(), 5);
tax = withoutTax.multiply(new BigDecimal(0.23), new MathContext(2));
table.setValueAt(tax.toPlainString(), table.getSelectedRow(), 7);
withTax = withoutTax.add(tax, new MathContext(5));
table.setValueAt(withTax.toPlainString(), table.getSelectedRow(), 8);
totalPrice.add(withTax, new MathContext(5));
paymentNum.setText(String.valueOf(totalPrice.toPlainString()));
Run Code Online (Sandbox Code Playgroud)
为什么我收到的totalPrice.add是在withoutTax.add工作正常的情况下被忽略了?
鉴于其链接,我想捕获一个在线视频(例如来自 YouTube)以进行进一步处理,而无需将其下载到磁盘上。我的意思是我想尽可能将它直接加载到内存中。根据这些链接:
http : //answers.opencv.org/question/24012/reading-video-stream-from-ip-camera-in-opencv-java/#24013
http://answers.opencv.org/question /24154/how-to-using-opencv-api-get-web-video-stream/#24156
http://answers.opencv.org/question/133/how-do-i-access-an-ip-camera /
https://pypi.org/project/pafy/
它应该是可行的。我的尝试是这样的:
import cv2
import pafy
vid = pafy.new("https://www.youtube.com/watch?v=QuELiw8tbx8")
vid_cap = cv2.VideoCapture()
vid_cap.open(vid.getbest(preftype="webm").url)
Run Code Online (Sandbox Code Playgroud)
但是它失败并出现错误
(python:12925): GLib-GObject-CRITICAL **: 14:48:56.168: g_object_set: assertion 'G_IS_OBJECT (object)' failed
False
Run Code Online (Sandbox Code Playgroud)
如何使用 python 实现我的目标?
我想从wav文件中获取一个频谱图,然后将其保存为png,但是我只需要图像的内容(而不是轴或其他任何东西)。我遇到了
Matplotlib绘制的这些问题:删除轴,图例和空白区域
scipy:没有框架,轴,仅内容的savefig
我也阅读了Matplotlib文档,但似乎无用,因此上述问题的答案已过时或我做错事是因为简单
plt.savefig('out.png', bbox_inches='tight', pad_inches=0)
不做我想实现的目标。最初,我尝试遵循此指南,但是代码崩溃了。然后,我尝试了这种方法,但是由于它已经过时,因此我对其进行了一些修改:
import matplotlib.pyplot as plt
from scipy.io import wavfile
import numpy as np
def graph_spectrogram(wav_file):
rate, data = wavfile.read(wav_file)
pxx, freqs, bins, im = plt.specgram(x=data, Fs=rate, noverlap=384, NFFT=512)
plt.axis('off')
plt.savefig('sp_xyz.png', bbox_inches='tight', dpi=300, frameon='false')
if __name__ == '__main__': # Main function
graph_spectrogram('...')
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
也许它不可见,但是内容周围有一个白色边框(从最大到最小):左,下,上,右。我想要相同的图像,但只包含内容,没有其他内容。我该如何实现?我使用python 3.6和Matplotlib 2.0.2。
我已经搜索了一整天,但仍然找不到解决我的问题的简单答案:当我在另一个单元格中编辑它时,如何使 JTable 单元格更新它的值?
我想以某种方式使用它,fireTableCellUpdated但我不太明白如何使用它、何时使用、在什么对象上使用。
我想要的是获得某种监听器来监听该值是否发生变化。在这个特定的场景中,我有可编辑的第三列,我在其中存储金额,并且我希望该侦听器自动计算并设置一行中其他单元格中的值。我想出了这样的东西:
@Override
public void tableChanged(TableModelEvent e)
{
BigDecimal withoutTax, tax, withTax;
for(int i = 0; i < table.getRowCount(); i++)
{
BigDecimal amount = new BigDecimal(String.valueOf(table.getValueAt(i, 3)).replace(",", "."));
BigDecimal price = new BigDecimal(String.valueOf(table.getValueAt(i, 4)).replace(",", "."));
withoutTax = amount.multiply(price, new MathContext(2));
table.setValueAt(withoutTax, i, 5);
tax = withoutTax.multiply(new BigDecimal(0.23), new MathContext(2));
table.setValueAt(tax, i, 7);
withTax = withoutTax.add(tax, new MathContext(2));
table.setValueAt(withTax, i, 8);
}
}
Run Code Online (Sandbox Code Playgroud)
但这会导致StackOverflowError我猜测这是因为table.setValueAt激发了tableChanged侦听器,所以它进入了无限循环。
有人可以解释一下我怎样才能做到这一点吗?
我想利用python的多处理模块来并行化这个简单的例子:
import numpy as np
import h5py
import os
import matplotlib.pyplot as plt
from multiprocessing import Pool
def load_array(path, variable):
try:
return np.array(h5py.File(path, "r").get(variable))
except:
raise FileNotFoundError("Corrupted file: {}".format(path))
def mat2img(rootdir, save_path, variable):
fig = plt.figure()
print("Processing " + rootdir)
for subdir, dirs, files in os.walk(rootdir):
for file in files:
arr = load_array(os.path.join(subdir, file), variable).T
fig.subplots_adjust(top=1, bottom=0, right=1, left=0)
plt.pcolormesh(np.arange(0, arr.shape[1]), np.arange(0, arr.shape[0]), arr, cmap="jet")
plt.axis("off")
plt.savefig(os.path.join(save_path, subdir.split(os.path.sep)[-1], file + ".jpg"))
plt.clf()
if __name__ == '__main__':
with Pool(processes=3) as pool: …Run Code Online (Sandbox Code Playgroud) python ×3
java ×2
bigdecimal ×1
currency ×1
jtable ×1
matplotlib ×1
opencv ×1
plot ×1
spectrogram ×1
swing ×1