我希望能够在图像上绘制一个矩形。我当时正在考虑使用Shiny制作应用程序,但首先需要弄清楚如何在图像上绘制矩形?有人有任何想法或指示吗?
我的想法是我需要对图像进行分层,我的图像始终为640x640像素,所以我的想法是在图像顶部上方形成一个640x640的矩阵,让我选择“像素”以创建矩形的边界?
编辑:我走得更远,现在我可以使用以下代码在有光泽的图像上进行绘制。
由于这些链接:
现在,当我绘制更多矩形时,我需要绘制多个矩形并将结果保留在绘图上。有什么想法吗?
library(shiny)
ui <- basicPage(
plotOutput("plot1",
click = "plot_click",
dblclick = "plot_dblclick",
hover = "plot_hover",
brush = "plot_brush"
),
verbatimTextOutput("info")
)
server <- function(input, output) {
library(jpeg)
output$plot1 <- renderPlot({
img <- readJPEG("street_1.jpg", native = TRUE)
# plot(anImage)
plot(1:640, type='n')
rasterImage(img,1,1,640,640)
}, height = 640, width = 640)
output$info <- renderText({
xy_str <- function(e) {
if(is.null(e)) return("NULL\n")
paste0("x=", round(e$x, 1), " y=", round(e$y, 1), "\n")
}
xy_range_str <- function(e) {
if(is.null(e)) return("NULL\n")
paste0("xmin=", round(e$xmin, …Run Code Online (Sandbox Code Playgroud)