- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我需要从太空天空探测太阳。
这些是输入图像的例子:
经过形态学过滤( open
操作两次)我得到了这样的结果
这里是这个处理的算法代码:
// Color to Gray
cvCvtColor(image, gray, CV_RGB2GRAY);
// color threshold
cvThreshold(gray,gray,150,255,CV_THRESH_BINARY);
// Morphologic open for 2 times
cvMorphologyEx( gray, dst, NULL, CV_SHAPE_RECT, CV_MOP_OPEN, 2);
这么简单的任务处理起来会不会太繁重了?以及如何找到太阳的中心?如果我找到白点,那么我会找到大地球的白点(第一个示例图像的左上角)
请告知我探测太阳的进一步行动。
更新 1:
尝试通过公式获取 centroid
的算法:{x,y} = {M10/M00, M01/M00}
CvMoments moments;
cvMoments(dst, &moments, 1);
double m00, m10, m01;
m00 = cvGetSpatialMoment(&moments, 0,0);
m10 = cvGetSpatialMoment(&moments, 1,0);
m01 = cvGetSpatialMoment(&moments, 0,1);
// calculating centroid
float centroid_x = m10/m00;
float centroid_y = m01/m00;
cvCircle( image,
cvPoint(cvRound(centroid_x), cvRound(centroid_y)),
50, CV_RGB(125,125,0), 4, 8,0);
而地球在照片中的位置,我得到了这样的结果:
所以,质心在地球上。 :(
更新 2:
尝试cvHoughCircles
:
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* circles = cvHoughCircles(dst, storage, CV_HOUGH_GRADIENT, 12,
dst->width/2, 255, 100, 0, 35);
if ( circles->total > 0 ) {
// getting first found circle
float* circle = (float*)cvGetSeqElem( circles, 0 );
// Drawing:
// green center dot
cvCircle( image, cvPoint(cvRound(circle[0]),cvRound(circle[1])),
3, CV_RGB(0,255,0), -1, 8, 0 );
// wrapping red circle
cvCircle( image, cvPoint(cvRound(circle[0]),cvRound(circle[1])),
cvRound(circle[2]), CV_RGB(255,0,0), 3, 8, 0 );
}
第一个例子:宾果游戏,但第二个 - 不是 ;(
我尝试了 cvHoughCircles()
的不同配置 - 找不到适合我的每张示例照片的配置。
更新 3:
matchTemplate
方法对我有用(mevatron
的响应)。它适用于大量测试。
最佳答案
试试简单的 matchTemplate
方法怎么样。我使用了这个模板图像:
而且,它检测到了我尝试过的 3 张太阳图像中的 3 张:
这应该是可行的,因为圆(在你的例子中是太阳)是旋转不变的,而且由于你离太阳太远,它也应该大致是尺度不变的。因此,模板匹配在这里可以很好地工作。
最后,这是我用来执行此操作的代码:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
/// Load image and template
string inputName = "sun2.png";
string outputName = "sun2_detect.png";
Mat img = imread( inputName, 1 );
Mat templ = imread( "sun_templ.png", 1 );
/// Create the result matrix
int result_cols = img.cols - templ.cols + 1;
int result_rows = img.rows - templ.rows + 1;
Mat result( result_cols, result_rows, CV_32FC1 );
/// Do the Matching and Normalize
matchTemplate(img, templ, result, CV_TM_CCOEFF);
normalize(result, result, 0, 1, NORM_MINMAX, -1, Mat());
Point maxLoc;
minMaxLoc(result, NULL, NULL, NULL, &maxLoc);
rectangle(img, maxLoc, Point( maxLoc.x + templ.cols , maxLoc.y + templ.rows ), Scalar(0, 255, 0), 2);
rectangle(result, maxLoc, Point( maxLoc.x + templ.cols , maxLoc.y + templ.rows ), Scalar(0, 255, 0), 2);
imshow("img", img);
imshow("result", result);
imwrite(outputName, img);
waitKey(0);
return 0;
}
希望对您有所帮助!
关于c++ - 如何在 OpenCv 中从太空天空检测太阳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8218997/
版本 java :10.0.1 Tomcat :8.0.36Ubuntu:18.04(64 位)Eclipse:光子(64 位) 错误:当我运行 Tomcat 服务器时,我发现了以下错误。请不要告诉我
我想将二进制文件传输到远程服务器。我为我的代码使用 SUN/ONC RPC(Linux 上的 rpcgen)。我正在使用 C。我已经为服务器和客户端编写了代码,它适用于文本文件,但是当我尝试传输二进制
我想在 Java 中使用 BouncyCaSTLe 和 PKCS11 库解密一个 CMSEnvelopedData。一切顺利,直到我遇到这个问题: 我可以成功检索收件人信息: CMSEnveloped
我低于异常 sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.ce
我在一个大型 Java 项目中工作,它有大约 400 个类。突然报错 sun.awt.image.PNGImageDecoder$PNGException: crc corruption at
我正在使用 Liferay v6.2 CE 并且出现以下错误: 2015 2:14:34 ΜΜ org.apache.catalina.startup.ContextConfig getServle
我正在学习 Java、Spring MVC 和 Eclipse。我现在正在读一本书,并试图让第一个 Spring MVC 示例运行。当我从 Eclipse 运行它时,出现此错误: INFO: TLD
我已经使用此命令创建了 CSR 请求: openssl req -out certificatecsr.csr -new -newkey rsa:2048 -keyout certificatekey
我们是三个开发 JSF 项目的人,我们之前没有接触过 JSF。奇怪的是,从 SVN check out 相同的数据,其中一名团队成员每次使用 Tomcat 7.0.27 时都会收到 404 错误。 T
我在 Apache Tomcat 7 上有一个 Web 应用程序,我的 Web 应用程序上有不受信任的证书。我的 Web 应用程序必须与另一个使用 https 的 Web 应用程序通信。但是我总是得到
在我运行以下代码时出现错误: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX
我已经从一台服务器迁移到一台新服务器。我为我的移动应用程序使用 PHP 网络服务来访问数据库中的数据。我已经安装了 SSL 证书,web 服务在浏览器和 iphone 应用程序(使用 ASIHTTPR
为什么在 HashMap 上调用 containsKey 比 get 慢? 测试:http://ideone.com/QsWXF (>15% 的差异,在 sun-jdk-1.6.0.17 上运行) 最
我是一名优秀的程序员,十分优秀!