- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想计算照片中对象的大小,其中包括目标对象和引用对象。
我想我想做的是这个软件实现的(我不知道这个软件有多精确)
https://itunes.apple.com/us/app/photo-meter-picture-measuring/id579961082?mt=8
我已经发现,总的来说,它被称为摄影测量,似乎是一个活跃的研究领域。
How would you find the height of objects given an image?
https://physics.stackexchange.com/questions/151121/can-i-calculate-the-size-of-a-real-object-by-just-looking-at-the-picture-taken-b
但是,我找不到
最佳答案
由于您的假设引用和目标在(大约)同一平面上。您可以应用中描述的方法“算法1:平面测量”
Antonio Criminisi. "Single-View Metrology: Algorithms and Applications(Invited Paper)". In: Pattern Recognition. Ed. by LucVan Gool. Vol. 2449. Lecture Notes in Computer Science. SpringerBerlin Heidelberg, 2002, pp. 224-239.
该方法允许您测量位于同一平面上的两点之间的距离。
基本上
P=H*p (1)
p
是图像中以齐次坐标表示的点,
P
是3D世界平面中的对应点,也用齐次坐标表示,而
H
是一个 3x3 矩阵,称为单应矩阵和
*
是矩阵向量乘法。
h11 h12 h13
H = h21 h22 h23
h31 h32 h33
p
的计量单位是像素,例如如果
p
是行
r
上的一个点和专栏
c
它将表示为
[r,c,1]
.
P
的计量单位是您的世界单位,例如米,您可以假设您的 3D 世界平面是平面
Z=0
等等
P
表示为齐次向量
[X,Y,1]
.
p1=[r1,c1,1]
和 p2=[r2,c2,1]
属于引用对象。 P1
和 P2
.您进行矩阵向量乘法,然后将结果向量除以第三个分量以获得齐次向量。P1=[X1,Y1,1]
是 P1=[(c1*h_12 + h_11*r1 + h_13)/(c1*h_32 + h_31*r1 + h_33),(c1*h_22 + h_21*r1 + h_23)/(c1*h_32 + h_31*r1 + h_33),1]
.暂时假设 H
的九个元素是无量纲的,这意味着 X1
的度量单位, Y1
, X2
, Y2
是像素。 R
之间P1
和 P2
即 R=sqrt(pow(X1-X2,2)+pow(Y1-Y2,2)
, R
仍然以像素表示。现在,由于 P1
和 P2
在引用对象上,这意味着您知道它们之间的距离(以米为单位),我们称该距离,以米为单位,M
. s
如 s=M/R
,尺寸s
是每像素米。 H
的每个元素相乘来自 s
并调用 G
你得到的新矩阵。现在G
的元素以米/像素表示。 p3
和 p4
属于目标对象。 p3
和 p4
通过 G
为了得到P3
和 P4
. P3=G*p3
和 P4=G*p4
.再次将每个向量除以它的第三个元素。P3=[X3,Y3,1]
和 P4=[X4,Y4,1]
现在 X3
, Y3
, X4
和 Y4
以米表示。 D
之间P3
和 P4
即 D=sqrt(pow(X3-X4,2)+pow(Y3-Y4,2)
. D
现在以米表示。 H
或者例如您可以使用 OpenCV
cv::findHomography
:基本上你需要现实世界中的点和图像中的点之间至少有四个对应关系。
H
在
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
void to_homogeneous(const std::vector< cv::Point2f >& non_homogeneous, std::vector< cv::Point3f >& homogeneous )
{
homogeneous.resize(non_homogeneous.size());
for ( size_t i = 0; i < non_homogeneous.size(); i++ ) {
homogeneous[i].x = non_homogeneous[i].x;
homogeneous[i].y = non_homogeneous[i].y;
homogeneous[i].z = 1.0;
}
}
void from_homogeneous(const std::vector< cv::Point3f >& homogeneous, std::vector< cv::Point2f >& non_homogeneous )
{
non_homogeneous.resize(homogeneous.size());
for ( size_t i = 0; i < non_homogeneous.size(); i++ ) {
non_homogeneous[i].x = homogeneous[i].x / homogeneous[i].z;
non_homogeneous[i].y = homogeneous[i].y / homogeneous[i].z;
}
}
void draw_cross(cv::Mat &img, const cv::Point center, float arm_length, const cv::Scalar &color, int thickness = 5 )
{
cv::Point N(center - cv::Point(0, arm_length));
cv::Point S(center + cv::Point(0, arm_length));
cv::Point E(center + cv::Point(arm_length, 0));
cv::Point W(center - cv::Point(arm_length, 0));
cv::line(img, N, S, color, thickness);
cv::line(img, E, W, color, thickness);
}
double measure_distance(const cv::Point2f& p1, const cv::Point2f& p2, const cv::Matx33f& GG)
{
std::vector< cv::Point2f > ticks(2);
ticks[0] = p1;
ticks[1] = p2;
std::vector< cv::Point3f > ticks_h;
to_homogeneous(ticks, ticks_h);
std::vector< cv::Point3f > world_ticks_h(2);
for ( size_t i = 0; i < ticks_h.size(); i++ ) {
world_ticks_h[i] = GG * ticks_h[i];
}
std::vector< cv::Point2f > world_ticks_back;
from_homogeneous(world_ticks_h, world_ticks_back);
return cv::norm(world_ticks_back[0] - world_ticks_back[1]);
}
int main(int, char**)
{
cv::Mat img = cv::imread("single-view-metrology.JPG");
std::vector< cv::Point2f > world_tenth_of_mm;
std::vector< cv::Point2f > img_px;
// Here I manually picked the pixels coordinates of the corners of the A4 sheet.
cv::Point2f TL(711, 64);
cv::Point2f BL(317, 1429);
cv::Point2f TR(1970, 175);
cv::Point2f BR(1863, 1561);
// This is the standard size of the A4 sheet:
const int A4_w_mm = 210;
const int A4_h_mm = 297;
const int scale = 10;
// Here I create the correspondences between the world point and the
// image points.
img_px.push_back(TL);
world_tenth_of_mm.push_back(cv::Point2f(0.0, 0.0));
img_px.push_back(TR);
world_tenth_of_mm.push_back(cv::Point2f(A4_w_mm * scale, 0.0));
img_px.push_back(BL);
world_tenth_of_mm.push_back(cv::Point2f(0.0, A4_h_mm * scale));
img_px.push_back(BR);
world_tenth_of_mm.push_back(cv::Point2f(A4_w_mm * scale, A4_h_mm * scale));
// Here I estimate the homography that brings the world to the image.
cv::Mat H = cv::findHomography(world_tenth_of_mm, img_px);
// To back-project the image points into the world I need the inverse of the homography.
cv::Mat G = H.inv();
// I can rectify the image.
cv::Mat warped;
cv::warpPerspective(img, warped, G, cv::Size(2600, 2200 * 297 / 210));
{
// Here I manually picked the pixels coordinates of ticks '0' and '1' in the slide rule,
// in the world the distance between them is 10mm.
cv::Point2f tick_0(2017, 1159);
cv::Point2f tick_1(1949, 1143);
// I measure the distance and I write it on the image.
std::ostringstream oss;
oss << measure_distance(tick_0, tick_1, G) / scale;
cv::line(img, tick_0, tick_1, CV_RGB(0, 255, 0));
cv::putText(img, oss.str(), (tick_0 + tick_1) / 2, cv::FONT_HERSHEY_PLAIN, 3, CV_RGB(0, 255, 0), 3);
}
{
// Here I manually picked the pixels coordinates of ticks '11' and '12' in the slide rule,
// in the world the distance between them is 10mm.
cv::Point2f tick_11(1277, 988);
cv::Point2f tick_12(1211, 973);
// I measure the distance and I write it on the image.
std::ostringstream oss;
oss << measure_distance(tick_11, tick_12, G) / scale;
cv::line(img, tick_11, tick_12, CV_RGB(0, 255, 0));
cv::putText(img, oss.str(), (tick_11 + tick_12) / 2, cv::FONT_HERSHEY_PLAIN, 3, CV_RGB(0, 255, 0), 3);
}
// I draw the points used in the estimate of the homography.
draw_cross(img, TL, 40, CV_RGB(255, 0, 0));
draw_cross(img, TR, 40, CV_RGB(255, 0, 0));
draw_cross(img, BL, 40, CV_RGB(255, 0, 0));
draw_cross(img, BR, 40, CV_RGB(255, 0, 0));
cv::namedWindow( "Input image", cv::WINDOW_NORMAL );
cv::imshow( "Input image", img );
cv::imwrite("img.png", img);
cv::namedWindow( "Rectified image", cv::WINDOW_NORMAL );
cv::imshow( "Rectified image", warped );
cv::imwrite("warped.png", warped);
cv::waitKey(0);
return 0;
}
关于image-processing - 使用照片中的引用对象测量对象的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35555375/
当我调用 png.Decode(imageFile) 时,它返回类型 image.Image。但我找不到将其转换为 image.NRGBA 或 image.RGBA 的记录方式,我可以在其上调用 At
image/jpeg 和 image/png 包有 Decode 和 Encode 函数,可以读取和写入 jpeg 和 png 图像,但 image/gif 包没有 - 只有 Decode 和 Dec
我正在尝试从一系列任意的非调色板图像创建动画 GIF。为了创建调色板图像,我需要以某种方式想出一个调色板。 // RGBA, etc. images from somewhere else var f
我在今年夏天的空闲时间使用 Go 镜像包进行一些练习。 package main import ( "os" "image" "image/png" "image/co
关闭。这个问题需要debugging details .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 1年前关闭。 Improve this question 今天
我正在尝试在 TilePane 中列出图像。当我尝试创建图像 new ImageView("address"); 时出现错误,地址如下: "file:D:/Chrysanthemum.jpeg/" 以
我有一个用于为画廊选择图像的表单,我希望允许用户仅选择 jpg、gif 和 png 图像格式。 现在,为了测试,我将图像的扩展名更改为 .bmp,例如“image1.bmp”,当我在输入文件中单击以选
我有创建图像的代码:(m_img 是 javafx.scene.image.Image) Image m_img = new Image("file:" + p_Fil.getAbsoluteFile
假设我有一个这样的 8 位灰度图像: var pixels []byte = ... width := 100 height := 100 如何将其转换为实现 image.Image 的东西? 最佳答
这段代码是我在localhost:8088 URL上的索引/主页的一部分,如果我想将用户发送到url localhost:8088/image/1,我应该写href='image/{{$image->
我正在尝试对图像进行简单的裁剪。这是代码 from PIL.Image import Image def get_image_half(image, half="upper"): if hal
我在这个问题上花了一整天,但在堆栈溢出中没有看到答案! 我试过了但是没用: >> pil_image = Image.frombytes('RGBA', wand_image.size, wa
所以,我是那些以始终使用最新版本的浏览器而自豪的人之一(当然 Internet Explorer 除外 - 我说的不是那个浏览器)。 我遇到了 this awesome CSS3 website详细介
如果 image_tag 无法从 url 加载图像,我想呈现默认图像: 因此,如果 image_tag 无法从 url 加载图像: 然后呈现默认值: 这将生成结果 HTML: 关于image -
我正在创建一个类似横幅的组件,并将图像设置为组件的背景,但我无法让它工作。我尝试了网上发布的不同建议,但没有成功,目前我不确定我的错误是否在 react 代码中,或者是 webpack 没有正确加载文
如何解决 Dart 中的这种歧义错误。 import 'dart:io'; import 'package:flutter/material.dart'; import 'package:camera
Center( child: CachedNetworkImage( imageUrl: "http:/ sosme link he
设置 www.website.com/sds/(index.htm) 以便鼠标悬停在不同位置时显示图像。 出于某种原因,当您将鼠标悬停在蓝色气球上时,图像 2.jpg 和 3.jpg(在蓝色气球上来回
社交网络在共享 URL 时可以很好地从网站中提取标题和描述,但对于图像,仍然需要创建自定义元标记:property="og:image" name="twitter:image" itemprop="
我正在尝试写一个简短的,它将读取一个 PNG 文件,并将一个 channel 与另一个 channel (R,G,B) 交换作为可能的选择。 但是,我无法找到如何从 image.At(x,y) 返回的
我是一名优秀的程序员,十分优秀!