Tag: stream

Node.js将相同的可读streampipe道化成多个(可写)目标

我需要运行两个需要从同一个stream中读取数据的命令。 在将一个stream传输到另一个stream之后,缓冲区被清空,所以我无法再从该stream读取数据,所以这不起作用: var spawn = require('child_process').spawn; var fs = require('fs'); var request = require('request'); var inputStream = request('http://placehold.it/640×360'); var identify = spawn('identify',['-']); inputStream.pipe(identify.stdin); var chunks = []; identify.stdout.on('data',function(chunk) { chunks.push(chunk); }); identify.stdout.on('end',function() { var size = getSize(Buffer.concat(chunks)); //width var convert = spawn('convert',['-','-scale',size * 0.5,'png:-']); inputStream.pipe(convert.stdin); convert.stdout.pipe(fs.createWriteStream('half.png')); }); function getSize(buffer){ return parseInt(buffer.toString().split(' ')[2].split('x')[0]); } 要求抱怨这个 Error: […]

计数汽车OpenCV + Python问题

我一直在试图计数过车时的车辆,它的工作原理,但问题是它计数一次车多次这是荒谬的,因为它应该算一次 这是我正在使用的代码: import cv2 import numpy as np bgsMOG = cv2.BackgroundSubtractorMOG() cap = cv2.VideoCapture("traffic.avi") counter = 0 if cap: while True: ret, frame = cap.read() if ret: fgmask = bgsMOG.apply(frame, None, 0.01) cv2.line(frame,(0,60),(160,60),(255,255,0),1) # To find the countours of the Cars contours, hierarchy = cv2.findContours(fgmask, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) try: hierarchy = hierarchy[0] except: hierarchy = [] for […]

Sankey Diagrams in R?

我试图用R中的Sankey图来显示我的数据stream。 我发现这个博客文章链接到一个R脚本,生成一个Sankey图,不幸的是它是相当原始的,有些有限(见下面的示例代码和数据)。 有没有人知道其他脚本 – 或者甚至是一个包 – 这是更发达? 我的最终目标是通过图组件的相对大小来可视化数据stream和百分比,就像这些Sankey图的例子 。 我在r-help列表上发布了一个类似的问题 ,但两周后没有任何反应,我试图在我的运气这里在stackoverflow。 谢谢,埃里克 PS。 我知道平行集合剧情 ,但这不是我正在寻找的。 # thanks to, https://tonybreyal.wordpress.com/2011/11/24/source_https-sourcing-an-r-script-from-github/ sourc.https <- function(url, …) { # install and load the RCurl package if (match('RCurl', nomatch=0, installed.packages()[,1])==0) { install.packages(c("RCurl"), dependencies = TRUE) require(RCurl) } else require(RCurl) # parse and evaluate each .R script sapply(c(url, …), function(u) { […]

节stream方法在N秒钟内调用M个请求

我需要一个组件/类,在N秒(或毫秒或毫微秒,无所谓)中将某些方法的执行限制为最大M个调用。 换句话说,我需要确保我的方法在N秒的滑动窗口中执行不超过M次。 如果你不知道现有的类可以自由发布你的解决scheme/想法你将如何实现这一点。

反序列化json数组stream一次一个项目

我将一个大对象的数组序列化为一个json http响应stream。 现在我想从这个stream反序列化这些对象。 有没有任何C#库,可以让我这样做? 我看了json.net,但似乎我不得不反序列化一次完整的数组对象。 [{large json object},{large json object}…..] 澄清:我想一次从stream中读取一个json对象并将其反序列化。

我怎样才能撰写输出stream,所以输出一次会有多个地方?

我想编写两个(或更多)stream成一个。 我的目标是任何针对cout , cerr和clog输出都会与原始stream一起输出到文件中。 (例如,当事情被logging到控制台,例如closures后,我想仍然能够返回并查看输出。) 我正在考虑做这样的事情: class stream_compose : public streambuf, private boost::noncopyable { public: // take two streams, save them in stream_holder, // this set their buffers to `this`. stream_compose; // implement the streambuf interface, routing to both // … private: // saves the streambuf of an ios class, // upon destruction restores it, […]

ifstream打开失败时如何获得错误信息

ifstream f; f.open(fileName); if ( f.fail() ) { // I need error message here, like "File not found" etc. – // the reason of the failure } 如何获取错误信息为string?

Tensorflow NaN错误?

我正在使用TensorFlow,并修改了教程示例以获取RGB图像。 这个algorithm在新的图像集合上完美地工作,直到突然(仍然收敛,通常约为92%的精确度),它与ReluGrad接收到非有限值的错误相冲突。 debugging表明,没有什么不寻常的事情发生的数字,直到非常突然,不明原因,错误抛出。 添加 print "max W vales: %g %g %g %g"%(tf.reduce_max(tf.abs(W_conv1)).eval(),tf.reduce_max(tf.abs(W_conv2)).eval(),tf.reduce_max(tf.abs(W_fc1)).eval(),tf.reduce_max(tf.abs(W_fc2)).eval()) print "max b vales: %g %g %g %g"%(tf.reduce_max(tf.abs(b_conv1)).eval(),tf.reduce_max(tf.abs(b_conv2)).eval(),tf.reduce_max(tf.abs(b_fc1)).eval(),tf.reduce_max(tf.abs(b_fc2)).eval()) 作为每个循环的debugging代码,产生以下输出: Step 8600 max W vales: 0.759422 0.295087 0.344725 0.583884 max b vales: 0.110509 0.111748 0.115327 0.124324 Step 8601 max W vales: 0.75947 0.295084 0.344723 0.583893 max b vales: 0.110516 0.111753 0.115322 0.124332 Step 8602 […]

使用urllib2stream式处理大型二进制文件

我使用下面的代码将大型文件从Internet传输到本地文件中: fp = open(file, 'wb') req = urllib2.urlopen(url) for line in req: fp.write(line) fp.close() 这工作,但它下载相当缓慢。 有更快的方法吗? (这些文件很大,所以我不想把它们留在内存中。)

Ruby on Rails 3:通过Rails将数据stream式传输到客户端

我正在开发与RackSpace云文件(类似于Amazon S3,但缺less某些function)的Ruby on Rails应用程序。 由于缺乏每个对象访问权限和查询stringauthentication的可用性,下载给用户必须通过应用程序进行调解。 在Rails 2.3中,它看起来像你可以dynamic构build一个响应,如下所示: # Streams about 180 MB of generated data to the browser. render :text => proc { |response, output| 10_000_000.times do |i| output.write("This is line #{i}\n") end } (来自http://api.rubyonrails.org/classes/ActionController/Base.html#M000464 ) 而不是10_000_000.times…我可以转储我的cloudfilesstream生成代码在那里。 麻烦的是,这是当我尝试在Rails 3中使用这种技术时得到的输出。 #<Proc:0x000000010989a6e8@/Users/jderiksen/lt/lt-uber/site/app/controllers/prospect_uploads_controller.rb:75> 看起来也许proc对象的call方法不被调用? 任何其他的想法?