gridify: Add Grids to Multiple png

Description Usage Arguments Value Considerations Note See Also Examples

Description

gridify - A wrapper function for grid_calc and plot_grid used to read in a directory of png files. Add grid lines. Output to directory.

gridify_pdf - A lighter weight version of gridify intended to be used as a part of the workflow for for larger jobs (though restricted to PDF file output).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
gridify(path = ".", out = file.path(path, "out"), pdf = TRUE,
  columns = 30, rows = columns, parallel = TRUE,
  cores = parallel::detectCores()/2, width = 6, height = 6,
  text.color = "gray60", text.size = 2, grid.size = 0.25,
  grid.color = text.color, fps = 4, size = "500x500", other.opts = "",
  crop = "", code.sheet = file.path(out, "embodied.csv"), duration = NULL,
  people = paste("person", 1:3, sep = "_"), clean = FALSE, bins = NULL,
  compress.pdf = TRUE, ...)

gridify_pdf(pngs, out = "out/pdf", columns = 30, rows = columns,
  parallel = TRUE, cores = parallel::detectCores()/2, width = 6,
  height = 6, text.color = "gray60", text.size = 2, grid.size = 0.25,
  grid.color = text.color, fps = 4, ...)

Arguments

path

Path to the in directory with the .png files or a single .mp4 file.

out

Path to the out directory.

pdf

logical. If TRUE a single .pdf (‘./raw/gridified.png’) is generated. This enables zooming and a single scrollable file. ghostscript must be installed and on your path.

columns

The number of grid columns.

rows

The number of grid rows.

parallel

logical. If TRUE attempts to run the function on multiple cores. Note that this may not mean a speed boost if you have one core or if the data set is smaller as the cluster takes time to create. For a visual representation of the use of parallel processing see: https://raw.github.com/trinker/embodied/master/inst/gridify_parallel_test/output.png

cores

The number of cores to use if parallel = TRUE. Default is half the number of available cores.

width

The width of the device.

height

The height of the device.

text.color

The color to make the coordinate labels.

text.size

The size of the coordinate labels.

grid.color

The color to make the grid.

grid.size

The thickness of the grid lines.

fps

The number of image frames per second to output. Generally the fps used to desconstruct a video into images will be used to reconstruct the images back to video.

size

Character string of the output size of the png files in the form of "width x height" (in px and no spaces).

other.opts

other options to be passed to ffmpeg.

crop

Character string of ffmpeg code used to crop the images (e.g. "-vf crop=in_w-2*120"). See: http://www.ffmpeg.org/ffmpeg-filters.html#crop for more.

code.sheet

A path to the embodied .csv coding sheet.

duration

An aptional duration of the original video, in seconds, if .png files are passed to path. This is used for code.sheet. Note that fps should also be set.

people

The people whose coordinates will be logged.

clean

logical. If TRUE and pdf = TRUE the directory with sequence of images will be removed after Gohstscript integration.

bins

The number of combined PDF files to make id pdf = TRUE. A value that is too low may cause the command line to hang indefinitly and/or yield and unweildy, multipage PDF file.

compress.pdf

logical. If TRUE, then compactPDF attempt to compress the multipaged PDFs generated by the bins argument.

...

other arguments passed to png.

pngs

A vector of paths to multiple png files.

Value

Returns multiple files with grid lines.

Considerations

Larger mp4 files may cause errors or unexpected hangups due to extended processig time and large file sizes. The user may want to consider breaking the job into smaller subcomponents and using elementary, non-wrapper functions including gridify_pdf). See the Example section for an example workflow utilizing this approach.

Note

Note that in order to properly view the time format column in the code.sheet, the user may need to adjust the .csv display settings when the .csv is opened. Within some spreadsheet programs, changing the format to a custom of hh:mm:ss.00 enables proper viewing.

See Also

plot_grid, mp4_to_png

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
## Not run: 
deb <- system.file("extdata", package = "embodied")
gridify(deb, "out")

#=============================#
# AN APPROACH FOR LARGER JOBS #
#=============================#

## Create png files from .mp4
loc <- "foo.mp4"
fps <- 4
x <- mp4_to_png(loc, fps = fps)

## Generate gridified pdfs
y <- folder(folder.name=file.path(x, "out"))
imgs <- dir(x)[grep("image-", dir(x))]
bins <- binify(file.path(x, imgs))
pdfs <- file.path(y, "pdfs")
lapply(bins, gridify_pdf, out=pdfs)

## Merge PDFs, compact PDF, clean up
library(tools)
z <- file.path(pdfs, dir(pdfs))
## size <- 500 #typically a good cut value
size <- 50
z2 <- binify(z, length(z)/size)
lapply(names(z2), function(x) {
    merge_pdf(z2[x], sprintf("%s/batch_%s.pdf", y, x))
    compactPDF(sprintf("%sbatch_%s.pdf", y, x))
    print(x)
    flush.console()
})
delete(pdfs)

## Code sheet
write_embodied(
    id = file_path_sans_ext(imgs),
    time = mp4_to_times(loc, fps = fps)[seq_along(imgs)],
    file = file.path(y, "coding.csv")
)

## End(Not run)

trinker/embodied documentation built on May 31, 2019, 8:42 p.m.