Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6860599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:25:43+00:00 2026-05-27T02:25:43+00:00

I need to detect the Sun from the space sky. These are examples of

  • 0

I need to detect the Sun from the space sky.

These are examples of the input images:


I’ve got such results after Morphologic filtering ( open operation for twice )


Here’s the algorithm code of this processing:

// 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);

Isn’t it too heavy processing for such a simple task? And how to find the center of the Sun? If I find white points, than I’ll find white points of big Earth ( left top corner on first example image )

Please advise me please my further action to detect the Sun.

UPDATE 1:

Trying algorithm of getting centroid by formula : {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);

And where Earth is in the photo, I got such a result:

So, centroid is on the Earth. 🙁

UPDATE 2:

Trying 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 ); 
}


First example: bingo, but the second – no ;(

I’ve tried different configuration of cvHoughCircles() – couldn’t find configuration to fit every my example photo.

UPDATE3:

matchTemplate approach worked for me ( response of mevatron ). It worked with big number of tests.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:25:43+00:00Added an answer on May 27, 2026 at 2:25 am

    How about trying a simple matchTemplate approach. I used this template image:
    enter image description here

    And, it detected the 3 out of 3 of the sun images I tried:
    enter image description here enter image description here enter image description here

    This should work due to the fact that circles (in your case the sun) are rotationally invariant, and since you are so far away from the sun it should be roughly scale invariant as well. So, template matching will work quite nicely here.

    Finally, here is the code that I used to do this:

    #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;
    }
    

    Hope you find that helpful!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to detect if a request cookie - value is different from a
i need to detect direction of my swipe gesture and i've got problem with
I need to detect if text input was processed by keyboard or some auto
I need to detect is my input string a file name or a directory
I need to detect a procedure from a click event has finished without delaying
I need to detect if a post contains a specific category from a JSONP
i need to detect from php if mysql query cache plugin is installed, any
I need to detect the current locale in OS X from the command line.
I need to detect when a session has expired in my Visuial Basic web
I need to detect whether my application is running within a virtualized OS instance

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.