[R] image processing and plotting at video rates ?
Hello R user I am using R now for some time and I like it a lot. I just started a new project where I am working with video streams at a resolution of 1024 x 768 pixels. I am reading the images out of a big raw file containing the uncompressed data. I do this via "readBin". As far as I have found out R has no build in support for image data to plot. Looking at CRAN has brought up "biOps" with many basic features for image processing as well as plotting. But the plotting speed quite bad (for video). By just reading the image data out of the file and plotting the image, without any further processing, I have frame rates less then a single frame per second on a 2,4 GHz dual-core Pentium. Here is the code I am using for (i in 1:500) { img <- imagedata( array(numCols, numRows, 3), type="rgb", ncol=numCols, nrow=numRows) tmp <- readBin(inFD, integer(), numCols * numRows * 4, 1, FALSE) img[,,] <- matrix(tmp, ncol=4, byrow=TRUE)[,1:3] #leaving out bgr[u] # in future here will be a segmentation and tracking algorithm plot( imgRotate90Clockwise( img ) ) } Does anybody has a tip? Is there a better choice for video image processing in R? Or, does native R support any internal speedup possibilities? Thank you for any help. Bye Philipp -- ________ Dipl.-Ing. Philipp Fechteler Department Image Processing Fraunhofer Institute for Telecommunications Heinrich-Hertz-Institut (HHI) Einsteinufer 37 10587 Berlin, Germany Phone +49 30 31002 616 Fax +49 30 31002 200 Email [EMAIL PROTECTED] WWW http://iphome.hhi.de/fechteler Visit us at 22. Treffpunkt Medizintechnik / Berlin, Germany / 22. May 2008 Lehrgebaeude der Charite Berlin / 9.00 - 17:30 Uhr http://www.tsbmedici.de ANGA Cable 2008 / Cologne, Germany / 27-29 May 2008 / Hall 10.3, Booth G38 http://www.angacable.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R script to start session (without automatically finishing)
Hello R friends I am quite impressed by the power of R, I am using it only since some weeks now. But its visualizing capabilities are outstanding! But one thing I couldn't solve: I have programs producing lots of data, most times 3D. In R I am using the library rgl to visualize nicely the 3D data. What I would like to do is to write R scipts which read in a data file and show me the 3D rgl plot. So that on the command line I just call my newly written R script, which pops up the rgl window. This session should run until I close the rgl window or press a button or something like this. Currently, I can write R scripts - using Rscript or - http://tolstoy.newcastle.edu.au/R/help/04/05/0500.html But both approaches contain the problem that the rgl window pops up for just a moment, and then the program terminates. Does any body has an idea, what to do? Help would be very appreciated. Thank's a lot and ... Marry Christmas + Happy New Year Philipp Dipl.-Ing. Philipp Fechteler Department Image Processing Fraunhofer Institute for Telecommunications Heinrich-Hertz-Institut (HHI) Einsteinufer 37 10587 Berlin, Germany Phone +49 30 31002 616 Fax +49 30 392 72 00 Email [EMAIL PROTECTED] WWW http://iphome.hhi.de/fechteler Visit us at FOE 2008 (8th Fiber Optics Expo) / Tokio Big Sight, Japan / 16 - 18 January 2008 / Booth 2 - 50 http://www.foe.jp/english __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R script to start session (without automatically finishing)
Hello Mr Ripley Prof Brian Ripley wrote: > So you have to write a script that will not terminate until you 'press a > button or something like this'. That's easy to do, but as you haven't > told us your OS. E.g. on Windows, call winDialogString at the end. > Thank you for helping. I am running on Linux. But I think the getchar() like call should be inside the R script. So is there something like this in R or any loadable module, e.g. a function sleeping until a key is pressed and returning the key code? Greetings Philipp > On Fri, 21 Dec 2007, Philipp Fechteler wrote: > >> Hello R friends >> >> I am quite impressed by the power of R, I am using it only since some >> weeks now. But its visualizing capabilities are outstanding! >> >> But one thing I couldn't solve: I have programs producing lots of data, >> most times 3D. In R I am using the library rgl to visualize nicely the >> 3D data. >> >> What I would like to do is to write R scipts which read in a data file >> and show me the 3D rgl plot. So that on the command line I just call my >> newly written R script, which pops up the rgl window. This session >> should run until I close the rgl window or press a button or something >> like this. >> >> Currently, I can write R scripts >> - using Rscript or >> - http://tolstoy.newcastle.edu.au/R/help/04/05/0500.html >> But both approaches contain the problem that the rgl window pops up for >> just a moment, and then the program terminates. >> >> >> Does any body has an idea, what to do? Help would be very appreciated. >> >> Thank's a lot and ... Marry Christmas + Happy New Year >> >> Philipp >> >> >> >> Dipl.-Ing. Philipp Fechteler >> Department Image Processing >> Fraunhofer Institute for Telecommunications >> Heinrich-Hertz-Institut (HHI) >> Einsteinufer 37 >> 10587 Berlin, Germany >> Phone+49 30 31002 616 >> Fax+49 30 392 72 00 >> Email[EMAIL PROTECTED] >> WWWhttp://iphome.hhi.de/fechteler >> > > -- Dipl.-Ing. Philipp Fechteler Department Image Processing Fraunhofer Institute for Telecommunications Heinrich-Hertz-Institut (HHI) Einsteinufer 37 10587 Berlin, Germany Phone +49 30 31002 616 Fax +49 30 392 72 00 Email [EMAIL PROTECTED] WWW http://iphome.hhi.de/fechteler Visit us at FOE 2008 (8th Fiber Optics Expo) / Tokio Big Sight, Japan / 16 - 18 January 2008 / Booth 2 - 50 http://www.foe.jp/english __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R script to start session (without automatically finishing)
Prof Brian Ripley wrote: > On Thu, 3 Jan 2008, Philipp Fechteler wrote: > >> Hello Mr Ripley >> >> Prof Brian Ripley wrote: >>> So you have to write a script that will not terminate until you >>> 'press a button or something like this'. That's easy to do, but as >>> you haven't told us your OS. E.g. on Windows, call winDialogString >>> at the end. >>> >> >> Thank you for helping. I am running on Linux. But I think the >> getchar() like call should be inside the R script. So is there >> something like this in R or any loadable module, e.g. a function >> sleeping until a key is pressed and returning the key code? > > See ?readline, and from Rscript scan("stdin", "", n=1). > The scan() function is quite near on my desired solution. But it inhabits the following problem. The rgl window pops up showing the data I want to see, but its frozen (due to the following scan() call). So I successfully see the data visualization as long as I want, but its a static view, the mouse-interactivity is lost (changing the viewing angle, zoom etc.). > > You can't do this totally portably: R might not be connected to a > terminal (even in interactive use: think ESS). You could also use a Tk > widget to give your users a button to press. > Is there anywere a short tutorial, how to mix R scripts with Tk? But the best would be to change the upper approach, so that the rgl window just keeps its interactivity. Thank you. Philipp >> >> >> Greetings >> Philipp >> >> >>> On Fri, 21 Dec 2007, Philipp Fechteler wrote: >>> >>>> Hello R friends >>>> >>>> I am quite impressed by the power of R, I am using it only since some >>>> weeks now. But its visualizing capabilities are outstanding! >>>> >>>> But one thing I couldn't solve: I have programs producing lots of data, >>>> most times 3D. In R I am using the library rgl to visualize nicely the >>>> 3D data. >>>> >>>> What I would like to do is to write R scipts which read in a data file >>>> and show me the 3D rgl plot. So that on the command line I just call my >>>> newly written R script, which pops up the rgl window. This session >>>> should run until I close the rgl window or press a button or something >>>> like this. >>>> >>>> Currently, I can write R scripts >>>> - using Rscript or >>>> - http://tolstoy.newcastle.edu.au/R/help/04/05/0500.html >>>> But both approaches contain the problem that the rgl window pops up for >>>> just a moment, and then the program terminates. >>>> >>>> >>>> Does any body has an idea, what to do? Help would be very appreciated. >>>> >>>> Thank's a lot and ... Marry Christmas + Happy New Year >>>> >>>> Philipp >>>> >>>> >>>> ________ >>>> >>>> Dipl.-Ing. Philipp Fechteler >>>> Department Image Processing >>>> Fraunhofer Institute for Telecommunications >>>> Heinrich-Hertz-Institut (HHI) >>>> Einsteinufer 37 >>>> 10587 Berlin, Germany >>>> Phone+49 30 31002 616 >>>> Fax+49 30 392 72 00 >>>> Email[EMAIL PROTECTED] >>>> WWWhttp://iphome.hhi.de/fechteler >>>> >>>> >>> >>> >> >> >> > -- Dipl.-Ing. Philipp Fechteler Department Image Processing Fraunhofer Institute for Telecommunications Heinrich-Hertz-Institut (HHI) Einsteinufer 37 10587 Berlin, Germany Phone +49 30 31002 616 Fax +49 30 392 72 00 Email [EMAIL PROTECTED] WWW http://iphome.hhi.de/fechteler Visit us at FOE 2008 (8th Fiber Optics Expo) / Tokio Big Sight, Japan / 16 - 18 January 2008 / Booth 2 - 50 http://www.foe.jp/english __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R script to start session (without automatically finishing)
Hello again I think now I can refine my problem: I want to run R scripts non-interactively in batch-mode or invoked in Perl scripts, with interactive rgl windows (responding to my mouse actions). Ideally the R script finishes when I close the rgl window and executes some last commands in the R script. When R is started non-interactively, by using Rscript or (in Linux) piping the input to the R process STDIN, then the rgl windows are not interactive. The only difference in the R environment I can find is, that the command interactive() returns TRUE only, when I have invoked R on the command line. In all other cases I have tried, this command returns FALSE. Does anybody now, how this interactive() function is working? In which way does it determine if R is running interactively or in batch mode? And how can I modify that behaviour or how can I simulate the interactive environment from a (Perl-) script calling my R script? Here is my Perl script approach for running R non-interacively, but non-successful simulating an interactive environment: use warnings; use strict; use English; use IPC::Open2; my @rScript = ( "library(rgl)\n", "rgl.open()\n", "rgl.bg(color=c(\"white\"))\n", "rgl.lines( c(0, 1, 1, 1, 1, 0, 0, 0), c(0, 0, 0, 1, 1, 1, 1, 0), c(0, 0, 0, 0, 0, 0, 0, 0), color=\"black\", size=2 )\n", "rgl.lines( c(0, 1, 1, 1, 1, 0, 0, 0), c(0, 0, 0, 1, 1, 1, 1, 0), c(1), color=\"black\", size=2 )\n", "rgl.lines( c(0, 0, 1, 1, 1, 1, 0, 0), c(0, 0, 1, 1, 0, 0, 1, 1), c(0, 1, 0, 1, 0, 1, 0, 1), color=\"black\", size=2 )\n" ); my $pid = open2( ">&STDOUT", my $R, "/usr/bin/R", "--slave","--quiet","--vanilla") or die "ERROR: can't open2 R: $ERRNO"; print $R @rScript; getc(); print $R "q()\n"; Thank's for help. Greetings Philipp Prof Brian Ripley wrote: > On Thu, 3 Jan 2008, Philipp Fechteler wrote: > >> Hello Mr Ripley >> >> Prof Brian Ripley wrote: >>> So you have to write a script that will not terminate until you >>> 'press a button or something like this'. That's easy to do, but as >>> you haven't told us your OS. E.g. on Windows, call winDialogString >>> at the end. >>> >> >> Thank you for helping. I am running on Linux. But I think the >> getchar() like call should be inside the R script. So is there >> something like this in R or any loadable module, e.g. a function >> sleeping until a key is pressed and returning the key code? > > See ?readline, and from Rscript scan("stdin", "", n=1). > The scan() function is quite near on my desired solution. But it inhabits the following problem. The rgl window pops up showing the data I want to see, but its frozen (due to the following scan() call). So I successfully see the data visualization as long as I want, but its a static view, the mouse-interactivity is lost (changing the viewing angle, zoom etc.). > > You can't do this totally portably: R might not be connected to a > terminal (even in interactive use: think ESS). You could also use a Tk > widget to give your users a button to press. > Is there anywere a short tutorial, how to mix R scripts with Tk? But the best would be to change the upper approach, so that the rgl window just keeps its interactivity. Thank you. Philipp >> >> >> Greetings >> Philipp >> >> >>> On Fri, 21 Dec 2007, Philipp Fechteler wrote: >>> >>>> Hello R friends >>>> >>>> I am quite impressed by the power of R, I am using it only since some >>>> weeks now. But its visualizing capabilities are outstanding! >>>> >>>> But one thing I couldn't solve: I have programs producing lots of data, >>>> most times 3D. In R I am using the library rgl to visualize nicely the >>>> 3D data. >>>> >>>> What I would like to do is to write R scipts which read in a data file >>>> and show me the 3D rgl plot. So that on the command line I just call my >>>> newly written R script, which pops up the rgl window. This session >>>> should run until I close the rgl window or press a button or something >>>> like this. >>>> >>>> Currently, I can write R scripts >>>> - using Rscript or >>>> - http://tolstoy.newcastle.edu.au/R/help/04/05/0500.html >>>> But both approaches contain the problem that the rgl window pops up for >>