Which points on the same curve?

  • Thread starter Thread starter sanane
  • Start date Start date
  • Tags Tags
    C++ Curve Points
Click For Summary
SUMMARY

The discussion focuses on identifying and saving three specific points on the same curve using OpenCV in C++. The user implements a program that reads an image, processes pixel data, and checks conditions based on the distance from predefined circles with radii 50, 73, and 15. The code utilizes structures and vectors to store coordinates and employs color manipulation to highlight points that meet the criteria. The main challenge is ensuring that points are accurately identified and stored without duplication.

PREREQUISITES
  • Understanding of C++ programming language
  • Familiarity with OpenCV 2.4.6 for image processing
  • Knowledge of geometric concepts related to circles
  • Experience with vector data structures in C++
NEXT STEPS
  • Explore advanced OpenCV functions for image segmentation
  • Learn about C++ memory management and optimization techniques
  • Investigate algorithms for point clustering and detection
  • Study the mathematical principles of curve fitting and interpolation
USEFUL FOR

Software developers, computer vision engineers, and data scientists interested in image processing and geometric analysis using OpenCV.

sanane
Messages
1
Reaction score
0
Hi everyone
ın fact at the beginning ı want to select three points every curve Idid it But now I shold find which points ont the same time AND THEN I shold save its How can do it

My code is here
C:
#include <iostream>
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/contrib/contrib.hpp"
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;
using namespace cv;
struct Koordinat {
        int x;
        int y;
};
int main()
{
        int const r1 = 50, r2 = 73, r3 = 15;
        std::vector<Koordinat> cember1, cember2, cember3;

        Mat image = imread("C:\\OpenCv2.4.6\\6.png");

        int ikiBoyutKarsilastirDizi[100][2] = {};
        int atlananKoordinatlar[100][2] = {};
        cv::Vec3b pixelColor(255, 255, 0);

        //circle( image, Point( 385, 385 ), 100.0, Scalar( 0, 0, 255 ), 1, 8 );
        //circle(image, Point(385, 385), 100, Scalar(255, 0, 0), 1, 8, 0);

        Vec3b color2 = image.at<Vec3b>(Point(394, 378));        for (int i = 0; i < image.cols; ++i) {  // row la sütunun yeri  yanlış olduğu için hesaplamalar yanlıs çıkıyor...
                for (int j = 0; j < image.rows; ++j) {
                      
                        Vec3b intensity = image.at<Vec3b>(j, i);
                        uchar blue = intensity.val[0];
                        uchar green = intensity.val[1];
                        uchar red = intensity.val[2];
                        //int b = int(image.at<cv::Vec3b>(i, j)[0]);
                        //int g = int(image.at<cv::Vec3b>(i, j)[1]);
                        //int r = int(image.at<cv::Vec3b>(i, j)[2]);
                        int x = 385, y = 385;

                        int cember_denklemi1;
                        int cember_denklemi2;
                        int cember_denklemi3;
                        //float cember_denklemi1, cember_denklemi2, cember_denklemi3;
                        ///**/
                        //cember_denklemi1 = sqrt((i - x)*(i - x) + (j - y)*(j - y) - (r1*r1));
                        //cember_denklemi2 = sqrt((i - x)*(i - x) + (j - y)*(j - y) - (r2*r2));
                        //cember_denklemi3 = sqrt((i - x)*(i - x) + (j - y)*(j - y) - (r3*r3));

                        cember_denklemi1 =  (i - x)*(i - x) + (j - y)*(j - y) - (r1*r1);
                          cember_denklemi2 = (i - x)*(i - x) + (j - y)*(j - y) - (r2*r2);
                        cember_denklemi3 = (i - x)*(i - x) + (j - y)*(j - y) - (r3*r3);
                        int sayac = 0;

              
                        if (cember_denklemi1 >=0 && cember_denklemi1 <=300&&(blue&&red&&green>0))
                        {
                              
                              
                                image.at<Vec3b>(Point(i, j)) = pixelColor;
                              
              

                              
                                //Vec3b color = image.at<Vec3b>(Point(i, j));
                                count << "gelen koordinat : " << i << " " << j << endl;
                                if (ikiBoyutKarsilastirDizi[0][0] == 0)
                                        //eğer dizinin içi boş ise vektörü ata. i ve j yi göster.
                                {
                                        ikiBoyutKarsilastirDizi[0][0] = i;
                                        ikiBoyutKarsilastirDizi[0][1] = j;
                                        count << "KIRMIZI" << i << " " << j << endl;
                      
                                //      image.at<Vec3b>(Point(i, j)) = color2;
                                }
                                else
                                {
                                        for (int z = 0; z<100; z++)//dizinin büyüklüğü 100 olduğu için.
                                        {
                                                if (ikiBoyutKarsilastirDizi[z][0] != 0 && ikiBoyutKarsilastirDizi[z][1] != 0)
                                                {
                                                      
/* 287 365 yüzünden and or oldu */if (abs(ikiBoyutKarsilastirDizi[z][0] - i) >= 5 || abs(ikiBoyutKarsilastirDizi[z][1] - j) >= 5) // eğer daha önce diziye atanmış vektörün x ve y'si yeni eklenmeye çalışan vektörün x ve y' sinden 5 fazla yada eksik mi kontrolü. abs'ın amacı -3 yada -2 çıkma durumunda olayı kurtarmak.
                                                        {
                                                              
                                                                sayac = z;
                                                      
                                                        }
                                                        else
                                                        {
                                                              
                                                                sayac = -1;
                                                                break;
                                                        }
                                                }
                                        }
                                      
                                        if (sayac != -1)
                                        {
                                              
                                                ikiBoyutKarsilastirDizi[sayac + 1][0] = i;
                                                ikiBoyutKarsilastirDizi[sayac + 1][1] = j;
                                                count << "KIRMIZI" << i << " " << j << endl;
                                      
                                        }
                                        else //atlanan koordinat buraya düşecek.
                                        {
                                                count << "atlanan koordinat: " <<i << " " << j << endl;
                                              
                                        }

                                }
                        }
                        int sayac2=0;
                         if (cember_denklemi2 >=0 && cember_denklemi2 <=300&&(blue&&red&&green>0))
                        {
                              
                              
                                image.at<Vec3b>(Point(i, j)) = pixelColor;
                              
              

                              
                                //Vec3b color = image.at<Vec3b>(Point(i, j));
                                count << "gelen koordinat1 : " << i << " " << j << endl;
                                if (ikiBoyutKarsilastirDizi[0][0] == 0)
                                        //eğer dizinin içi boş ise vektörü ata. i ve j yi göster.
                                {
                                        ikiBoyutKarsilastirDizi[0][0] = i;
                                        ikiBoyutKarsilastirDizi[0][1] = j;
                                        count << "BUYUK" << i << " " << j << endl;
                      
                                //      image.at<Vec3b>(Point(i, j)) = color2;
                                }
                                else
                                {
                                        for (int z = 0; z<100; z++)//dizinin büyüklüğü 100 olduğu için.
                                        {//0 0 geldiğinde 5 ten büyük gözüktüğü için dahil ediyor 0'lar için özel bir şey lazım.
                                                if (ikiBoyutKarsilastirDizi[z][0] != 0 && ikiBoyutKarsilastirDizi[z][1] != 0) // birinci yada ikinci değer 0 değilse aramaya devam et.
                                                {
                                                      
/* 287 365 yüzünden and or oldu */if (abs(ikiBoyutKarsilastirDizi[z][0] - i) >= 5 || abs(ikiBoyutKarsilastirDizi[z][1] - j) >= 5)
                                                        {
                                                              
                                                              
                                                                sayac2 = z;
                                                      
                                                        }
                                                        else
                                                        {
                                                              
                                                                sayac2 = -1;
                                                                break;
                                                        }
                                                }
                                        }
                                        //bütün değerlerin kontrolü yapıldıktan sonra eleman eklenmeli ve gösterilmeli.
                                        if (sayac2 != -1)
                                        {
                                              
                                                ikiBoyutKarsilastirDizi[sayac2 + 1][0] = i;
                                                ikiBoyutKarsilastirDizi[sayac2 + 1][1] = j;
                                                count << "BUYUK" << i << " " << j << endl;
                                      
                                        }
                                        else //atlanan koordinat buraya düşecek.
                                        {
                                                count << "atlanan koordinat1: " <<i << " " << j << endl;
                                              
                                        }

                                }
                        }
                        int sayac3=0;
                       
                        if (cember_denklemi3 >=0 && cember_denklemi3 <=300&&(blue&&red&&green>0))
                        {
                              
                              
                                image.at<Vec3b>(Point(i, j)) = pixelColor;
                              
              

                              
                                //Vec3b color = image.at<Vec3b>(Point(i, j));
                                count << "gelen koordinat2 : " << i << " " << j << endl;
                                if (ikiBoyutKarsilastirDizi[0][0] == 0)
                                        //eğer dizinin içi boş ise vektörü ata. i ve j yi göster.
                                {
                                        ikiBoyutKarsilastirDizi[0][0] = i;
                                        ikiBoyutKarsilastirDizi[0][1] = j;
                                        count << "KUCUK" << i << " " << j << endl;
                      
                                //      image.at<Vec3b>(Point(i, j)) = color2;
                                }
                                else //dizinin ilk elemanı atanmış ise karşılaştırma yap 5 fark kuralına uygunsa diziye ekle, uygun değilse vektörü atla. Atladıysan vektörü gösterme atlamadıysan vektörü göster.
                                {
                                        for (int z = 0; z<100; z++)//dizinin büyüklüğü 100 olduğu için.
                                        {//0 0 geldiğinde 5 ten büyük gözüktüğü için dahil ediyor 0'lar için özel bir şey lazım.
                                                if (ikiBoyutKarsilastirDizi[z][0] != 0 && ikiBoyutKarsilastirDizi[z][1] != 0) // birinci yada ikinci değer 0 değilse aramaya devam et.
                                                {
                                                      
/* 287 365 yüzünden and or oldu */if (abs(ikiBoyutKarsilastirDizi[z][0] - i) >= 5 || abs(ikiBoyutKarsilastirDizi[z][1] - j) >= 5) // eğer daha önce diziye atanmış vektörün x ve y'si yeni eklenmeye çalışan vektörün x ve y' sinden 5 fazla yada eksik mi kontrolü. abs'ın amacı -3 yada -2 çıkma durumunda olayı kurtarmak.
                                                        {// Doğruysa,atlamadığımız için karşılaştırma dizisine ata,göster.
                                                                //sürekli olarak 1'e yada 0 a kaydediyor dizideki ilk 0 indisini bul demek lazım.iptal kontrolü dışarı çıkar.
                                                              
                                                                sayac3 = z;
                                                      
                                                        }
                                                        else
                                                        {
                                                              
                                                                sayac3 = -1;
                                                                break;
                                                        }
                                                }
                                        }
                                        //bütün değerlerin kontrolü yapıldıktan sonra eleman eklenmeli ve gösterilmeli.
                                        if (sayac3 != -1)
                                        {
                                              
                                                ikiBoyutKarsilastirDizi[sayac3 + 1][0] = i;
                                                ikiBoyutKarsilastirDizi[sayac3 + 1][1] = j;
                                                count << "KUCUK" << i << " " << j << endl;
                                      
                                        }
                                        else //atlanan koordinat buraya düşecek.
                                        {
                                                count << "atlanan koordinat2: " <<i << " " << j << endl;
                                              
                                        }

                                }
                        }
                       
                }
        }
        imshow("Image", image);
        int k = waitKey();
           imwrite("5.jpg", image);
        //waitKey( 0 );
        return(0);
}
 
Last edited by a moderator:
Physics news on Phys.org
I am sorry. But your description is not clear enough. From your code I can see your native language is Turkish and you probably cannot speak or write English too well. If you want to program on a professional level in the future I urge you to learn English.
In the professional world software is documented in English so that everyone can understand your program. And when you want to build upon a program from someone else it would be very difficult to do so if it was written in a language you don't understand
 

Similar threads

  • · Replies 23 ·
Replies
23
Views
9K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 3 ·
Replies
3
Views
4K