Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Opencv python code to C++ transfer

Status
Not open for further replies.
I want this opencv example to run on C:
Well start translating the code...the sooner you start the sooner it will be done...

Oh, wait you are expecting someone to do your job for you. That is not the function of this forum, perhaps you should hire a consultant to do the work for you.
 

No its not my work. I just want to understand watershade
whats more I dont know python at all.
And the c++ code is alot harder for someone who just started the subject.
Or at least can you give me the varieble types I should use like mat or vector as I dont understand them very well as well as in this code or perhapes python as a whole you dont use variebles type at all.

- - - Updated - - -

Here is what I did so far I didn't want to upload my code because I am ashamed of it but maybe you will think otherwise
Code:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/core/operations.hpp>
#include "opencv2/core/cvdef.h"
#include "opencv2/core/version.hpp"
#include "opencv2/core/base.hpp"
#include "opencv2/core/cvstd.hpp"
#include "opencv2/core/traits.hpp"
#include "opencv2/core/matx.hpp"
#include "opencv2/core/types.hpp"
#include "opencv2/core/mat.hpp"
#include "opencv2/core/persistence.hpp"


using namespace std;
using namespace cv;

int main(void)

{
    RNG rng(12345);

    //Mat src = imread("daA2500-14uc__21706175__20170522_162253225_0001.tiff");

    Mat src = imread("daA2500-14uc__21706175__20170522_162253225_0100.tiff");


    Mat bw;

    cvtColor(src,bw,CV_BGR2GRAY);

    Mat thresh;

    Mat thresh1;

    double ret = threshold(bw,thresh,0,255,THRESH_BINARY | THRESH_OTSU);

    Mat kernel = Mat(3, 3, CV_8U);

    Mat opening;

    morphologyEx(thresh,opening,MORPH_OPEN,kernel,Point(-1,-1),2);

    Mat sure_bg;

    dilate(opening,sure_bg,kernel,Point(-1,-1),3);

    Mat dist_transform;
    Mat labels;

    distanceTransform(opening,dist_transform,labels,DIST_L2,5);

    double minn,maxx;

    minMaxLoc(dist_transform,&minn,&maxx);

    Mat sure_fg;

    double ret1 = threshold(dist_transform, sure_fg, 0.7*maxx, 255,0);

    sure_fg.convertTo(sure_fg,CV_8U);

    Mat unknown;

    subtract(sure_bg,sure_fg,unknown);

    Mat markers;

    double ret2 = connectedComponents(sure_fg,markers);

    markers = markers + Scalar::all(1);

    //add(markers,Scalar::all(1),markers);

    for(int i=0; i<unknown.rows; i++)
    {
        for(int j=0; i<unknown.cols; j++)
        {
            if (unknown.at<int>(i,j) == 255)
            {
                markers.at<int>(i,j) = 0;
            }
        }
    }

    watershed(src,markers);


    for(int i=0; i<markers.rows; i++)
    {
        for(int j=0; i<markers.cols; j++)
        {
            if (markers.at<int>(i,j) == -1)
            {
                src.at<Vec3b>(i,j) = Vec3b(255, 0, 0);
            }
        }
    }
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top