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 8375909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:17:48+00:00 2026-06-09T15:17:48+00:00

In some reason google does not have good examples of using cvCalcPGH() nor other

  • 0

In some reason google does not have good examples of using cvCalcPGH() nor other good examples of using Freeman code for contour matching. So I try to make it:

#include "opencv2/opencv.hpp"
#include "opencv2/legacy/legacy.hpp"

int
main(int argc, char* argv[]) {

        IplImage* g_gray = cvLoadImage("lisa.png",CV_LOAD_IMAGE_GRAYSCALE);
        cvThreshold( g_gray, g_gray, 100, 255, CV_THRESH_BINARY );

        CvMemStorage* storage=cvCreateMemStorage(0);
        CvSeq* firstContour=NULL;

        int a=cvFindContours(g_gray, storage, &firstContour,sizeof(CvChain),CV_RETR_LIST, CV_CHAIN_CODE);

        CvHistogram *hist;
        int h_bins = 30, s_bins = 30;
        float h_ranges[] = { 0, 180 };
        float s_ranges[] = { 0, 255 };
        int hist_size[] = { h_bins, s_bins };
        float* ranges[] = { h_ranges, s_ranges };

        hist = cvCreateHist( 2, hist_size, CV_HIST_ARRAY, ranges, 1 );
        if( CV_SEQ_ELTYPE( firstContour ) != CV_32SC2 ) {
                printf(":(\n");
        }

        cvCalcPGH((CvSeq *)firstContour,hist);
        return 0;

}

cvFindContours() will run as documented but cvCalcPGH() will fail:

$ ./calcpgh 
:(
OpenCV Error: Unsupported format or combination of formats (The contour is not valid or the point type is not supported) in cvCalcPGH, file /Users/tonu-samuel/OpenCV-2.4.2/modules/legacy/src/pgh.cpp, line 351
terminate called throwing an exceptionAbort trap: 6
$

OpenCV is 2.4.2 and indicated assert() is for CV_SEQ_ELTYPE( contour ) != CV_32SC2 I check also in my code. How to fix it unsure.

  • 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-06-09T15:17:49+00:00Added an answer on June 9, 2026 at 3:17 pm

    The reason google won’t give you good examples, is all the things you are talking about are deprecated.

    cvCalcPGH is not anymore available in the new opencv, which you may already know as you have included legacy libraries.

    Also the CV_CHAIN_CODE is removed and you can’t use it in the new opencv.

    You should find the time to port your code to the new opencv which is trending and will get more help from others.

    But discussing your current code, as the old documentation says:

    CV_CHAIN_CODE – outputs contours in the Freeman chain code. All other
    methods output polygons (sequences of vertices)

    The output of cvFindContours is always sequences of vertices and CV_CHAIN_CODE is just an exception. That’s why cvCalcPGH couldn’t understand these codes.

    And as you may have already tested the code with other approximation methods, you should’ve seen that the cvCalcPGH works fine with polygons.

    You should convert the Freeman code to polygons yourself, then you can use any opencv methods you want. But without that, I have not seen a single method that can interpret the Freeman code itself.

    I’m not sure how exactly this conversion should be done, but using the code below, which is shamelessly stolen from Sara Maher Mohammad, you may extract the codes and start interpreting it yourself:

    CvChainPtReader reader;
    
    cvStartReadChainPoints((CvChain*) firstContour, &reader);
    for (int i = 0; i < firstContour->total; i++) {
        CV_READ_SEQ_ELEM(reader.code, (*((CvSeqReader*)&(reader))));
        printf("%d \n", reader.code);
    }
    

    But again, I don’t recommend working on deprecated methods and functions, you may find better ways to do what you want.

    Just guessing that you may just want to find the distance between two Freeman codes, you may just stay out of calculating PGH, and just use some other distance functions like the one discussed here.

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

Sidebar

Related Questions

I have this code, and for some reason my $.post function fires twice in
For some reason, the Google API expects longs instead of objects (like Color). What
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
I found some sample code posted at https://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/4d45e9ea5471cba4/4519371a77ed4a74?hl=en&pli=1 for self installing a Windows Service.
I have this code $(#inputId).keyup(function(){ alert($(#inputId).val()); }); I know this is fairly basic(I'm not
I have a very strange issue that only affects webkit browsers for some reason,
due to some unavoidable reasons I need to disable Google Chrome's Chrome PDF Viewer
for some reason when I try to call CocoaAsyncSocket's onSocket:didReadData:withTag method, it's failing and
For some reason I can't detect I can't set a z index for any
For some reason there's a variable called d that is defined immediately after I

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.