视频文件从R中外部源转换为像素

问题描述 投票:0回答:1

我想创建与图像处理线表语模型,我在我的谷歌驱动器有大量的视频文件(.MOV)(涉及自动驾驶),我从谷歌驾车的数据链接到文件。我的磁盘和数据可用于所有互联网用户。

test

https://drive.google.com/drive/folders/1JidqB3TfHn0Cky8VBXHjbmHu7s0rGLrO?usp=sharing

train

https://drive.google.com/drive/folders/1WIFQIC23_o1__BPmlRDpnYYwmthH2AP-?usp=sharing

library("googledrive") 

X=googledrive::drive_ls(path ="test")
Label=googledrive::drive_ls(path ="train")

因此,从谷歌盘(如果必要的话)数据帧的示例性结构

dput()

train=structure(list(name = structure(c(1L, 11L, 10L, 9L, 8L, 7L, 6L, 
5L, 4L, 3L, 2L), .Label = c("<chr>", "047a188c-1ac1965c.mov", 
"047a7ecb-68221e4a.mov", "047c278b-452d36f8.mov", "047e715f-3e47a9aa.mov", 
"047e715f-81e81a28.mov", "047e732b-aa79a87d.mov", "0571873b-de675e01.mov", 
"0571873b-faf718b2.mov", "0573e933-a8b4cf7d.mov", "0573f031-8ef23cf6.mov"
), class = "factor"), id = structure(c(1L, 5L, 7L, 11L, 9L, 3L, 
10L, 8L, 4L, 2L, 6L), .Label = c("<chr>", "115rWp3h3Of3Rx61mqDRfhatFMFOpImRf", 
"1EfokXp8UAxYKlpmGAIwU3FRJTTqrgDrS", "1EJa-A0a4_4nVgeF-pBXh6q6DFToGTYFu", 
"1HHML9bo4UPY9r1hIL9igSX_t5FXH5n82", "1HzVTOqRwNfxVDey6EYmDe2nd8hnnTbHT", 
"1IhMQiiCyb_WcKif8qyQmeK1W0tb8iU-U", "1lQc1a0mFw158T9U_QRvgoF0a33xiehZc", 
"1StqEC_7hJO4HJ9uvC0o7sjLLY3tdceNp", "1thEsWrcYFN4qgG57RCUxqCr7WE6ecrmq", 
"1xcxAuHamoFKHCD05wHfdVjeVDEN-FW8C"), class = "factor"), drive_resource = structure(c(2L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("<list [41]>", 
"<list>"), class = "factor")), .Names = c("name", "id", "drive_resource"
), class = "data.frame", row.names = c(NA, -11L))



test=structure(list(name = structure(c(1L, 2L, 4L, 3L, 11L, 10L, 9L, 
8L, 7L, 6L, 5L), .Label = c("<chr>", "ddbd3eb2-ed0fde54.mov", 
"ddbf7bbb-c1908e76.mov", "ddd140cc-c54a4e82.mov", "df94066c-654dcae9.mov", 
"df94066c-b5e96c4c.mov", "df952550-4cb35087.mov", "df9b2e94-c14fc6a7.mov", 
"df9b8801-a11fba46.mov", "df9cc07f-5cec2c16.mov", "dfa06e5c-aa220d9a.mov"
), class = "factor"), id = structure(c(1L, 10L, 2L, 3L, 8L, 6L, 
11L, 7L, 9L, 4L, 5L), .Label = c("<chr>", "18fDVBhfyAHqUffG0GNFGti7549G43bhZ", 
"1aYVn6L7147dDPcOb5CKC3RHh28fS7qix", "1Evm3EotD1xRoljlVCZ3sDIMnEmKaTbO5", 
"1jhbfo3NSKKjbLrMkEh-HRx-UIOUr6R5o", "1kK5AvfwTV_exoWO55dEwEH4QIHaqpVER", 
"1mjr8xSRdULPbmkQN-7L5Dx9yMb_zLxWh", "1OSg6d4q9is80c9Oark6ktdXwvZI8IpER", 
"1Q3UlVeZXDF2cjglqxToapX2FMgRABhA9", "1uIS-Y3N_ipDuzG8kVT5gP3VScAvS-B9_", 
"1yXKCCfgMJVbLqEyTJJCjS_pKQLMnZ6Kp"), class = "factor"), drive_resource = structure(c(2L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("<list [41]>", 
"<list>"), class = "factor")), .Names = c("name", "id", "drive_resource"
), class = "data.frame", row.names = c(NA, -11L))

为了进行分析,我必须视频和(或)图像转换为像素,在我的情况下,它是视频,所以我这样做。

require(EBImage)
# Dataframe of resized images
rs_df <- data.frame()

# Main loop: for each image, resize and set it to greyscale
for(i in 1:nrow(X))
{
  # Try-catch
  result <- tryCatch({
    # Image (as 1d vector)
    img <- as.numeric(X[i,])
    # Reshape as a 64x64 image (EBImage object)
    img <- Image(img, dim=c(64, 64), colormode = "Grayscale")
    # Resize image to 28x28 pixels
    img_resized <- resize(img, w = 28, h = 28)
    # Get image matrix (there should be another function to do this faster and more neatly!)
    img_matrix <- [email protected]
    # Coerce to a vector
    img_vector <- as.vector(t(img_matrix))
    # Add label
    label <- labels[i,]
    vec <- c(label, img_vector)
    # Stack in rs_df using rbind
    rs_df <- rbind(rs_df, vec)
    # Print status
    print(paste("Done",i,sep = " "))},
    # Error function (just prints the error). Btw you should get no errors!
    error = function(e){print(e)})
}

之后我与喜欢的错误列表

下一个

names(rs_df) <- c("label", paste("pixel", c(1:776))) #776 video .mov files

我认为视频是不是在装R.我不知道为什么。我需要帮助。

作为输出我想是这样

   label pixel.1 pixel.2 pixel.3 pixel.4 pixel.5 pixel.6 pixel.7
1    304     304     304     304     304     304     304     304
2     32      32      32      32      32      32      32      32
3    350     351     351     351     351     351     351     351
4    265     265     265     265     265     265     265     265
5    108     108     108     108     108     108     108     108
6     87      87      87      87      87      87      87      87
7    191     192     192     192     192     192     192     192
8    170     170     170     170     170     170     170     170
9    329     329     329     329     329     329     329     329
10   268     268     268     268     268     268     268     268
11   238     238     238     238     238     238     238     238
12   159     159     159     159     159     159     159     159
13   220     221     221     221     221     221     221     221

如何videodatat转换为像素数据帧。谢谢。

r dataframe image-processing
1个回答
0
投票

我得到的回答这里https://github.com/apache/incubator-mxnet/issues/14061打包成像仪。

© www.soinside.com 2019 - 2024. All rights reserved.