Jump to content

Zyga

Members
  • Posts

    36
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by Zyga

  1. Hi all,

    I wrote some code that uses functionalities from lvanlys.dll, so it appears as dependant item in project explorer just like other dlls that I'm linking to (e.g. nivision.dll).
    When I want to distribute my code as lvlib, lvanlys.dll is copied to destination directory (and worse it becomes part of the lvlib) what causes future conflicts in a project where I use created library. No other dlls are acting like this, only lvanlys.dll. What is the difference between them? How i can avoid of copying this file?

    Best regards,
    Zyga

  2. Thanks for repty.
    my function ptotype:
    float Calibrate(float *APoints, int32_t *Asize, int32_t width, int32_t height, float squareSize);
    And LabVIEW call:
    post-27557-0-19450500-1422400009.png
    If I remove:
    double rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs);
    from compiled code, functions works. Non of from LabVIEW data is used to call this function.
    objectPoints is a vector created from Apoints  by arr2vect() while Asize is used to properly place elements in mentioned vector.

  3. Hi everyone. 
    I wrote wrapper in Visual Studio for OpenCV calibrateCamera() function. Every operation like converting 1D array of points to vector<vector<Point2f>>  etc, works ok, except most important thing.
    When function ()calibrateCamera is called, LabVIEW crashes. When this line is commented out, dll works ok (at least labview is still alive). Im out of ideas. I suspect that this is problem with memory management but i dont have an idea where it cames from. Function do not operate directly on data passed from LabVIEW.

    Ultimately I can compile code as exe and call it via cmd, but I'm curious why such a thing appears.

     

    Thanks for your precious time!
    Zyga


    dll source (if you need i can enclose some sample input data):

     

    #include <opencv2/core/core.hpp>
    #include <opencv2/calib3d/calib3d.hpp>
    #include <extcode.h>

    using namespace cv;
    using namespace std;


    static void calcBoardCornerPositions(Size boardSize, float squareSize, vector<Point3f> &corners);
    static void arr2vect(float *APoints,int *Asize, vector<vector<Point2f>> &imagePoints);

    extern "C"
    {
        float __declspec(dllexport)

    Calibrate(float *APoints, int *Asize, int width, int height, float squareSize)
    {
        //initialize variables
        vector<vector<Point2f>> imagePoints;
        Size boardSize;
        boardSize.height = height; boardSize.width = width;
        Mat cameraMatrix = Mat::eye(3, 3, CV_64F), distCoeffs = Mat::zeros(1, 1, CV_64F);
        cameraMatrix.at<double>(0,0) = 1.0;
        vector<Mat> rvecs, tvecs;
        vector<vector<Point3f>> objectPoints(1);
        Size imageSize; imageSize.width = 2040; imageSize.height = 2040;

    arr2vect(APoints, Asize, imagePoints); // prepare imagePoints
    calcBoardCornerPositions(boardSize, squareSize, objectPoints[0]); //prepare objectPoints
    objectPoints.resize(imagePoints.size(),objectPoints[0]);

    //calibrate
    double rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs);
    return rms;
    }
    }

     

     

    //definitions
    static void arr2vect(float *APoints,int *Asize, vector<vector<Point2f>> &imagePoints)
    {
        int page = *(Asize); int row = *(Asize+1); int col = *(Asize +2);
        Point2f pointBuf;
        vector<Point2f> vectBuf;

        for (int i = 0; i<page; i++)
        {
            for (int j = 0; j<row; j++)
            {
                pointBuf.x = *(APoints + (i*(row*col))+j*2);
                pointBuf.y = *(APoints + (i*(row*col))+j*2+1);
                vectBuf.push_back(pointBuf);
            }
            imagePoints.push_back(vectBuf);
            vectBuf.clear();
        }
        vectBuf.clear();
    }

    static void calcBoardCornerPositions(Size boardSize, float squareSize, vector<Point3f> &corners)
                                        
    {
        corners.clear();
                for( int i = 0; i < boardSize.height; ++i )
                     for( int j = 0; j < boardSize.width; ++j )
                         corners.push_back(Point3f(float( j*squareSize ), float( i*squareSize ), 0));   

    }

  4. Stick to C# entirely is nat an option for me (at least for now). I don't know c#. But i'm familiar enough with labview to do things i want to do. I'll do some test and we will see.
    Thanks for help and for useful references. If I handle with this I'll post my solution.


  5. Right, but Constructor Node says that ISldWorks class has no public constructors. I assume that IsldWorks class is an abstract class. A Few weeks ago I faced the same problem. How to use .net abstract class in LV and I did that just by creating .net reference and pointinting that specific class. Im not real OO developer so my reasoning and might be wrong but it worked.

     

    Thanks to your tips i came across on information that i can create some wrapper in c# that could return proper reference. Do you think it is possible and it could work?

     

     

  6. There is online documentation under this adress.
    For now i just want to create top-level object ISldWorks from SolidWorks.Interop.sldworks.dll and for example, simply call RevNumber() method. Same action in Visual Studio works fine.

     

    Sub Main()
            Dim app As SldWorks = CreateObject("SldWorks.Application")
            Dim revNmb As String = app.RevisionNumber
        End Sub

    Only thing i did is to add SolidWorks.Interop.sldworks.dll to a reference library.

    In LabView i acces to a ISldWorks class by creating .net referece and manually browsing to dll (static class? Not sure that is proper naming). As a result is empty reference.
    xjzcDxTO.png

    By the way, thanks for reply!

  7. Hi Everyone.
    As in topic, i try to use SolidWoks API, but I cannot proper open reference to any object (via constructor node and creating static ref).
    Im getting error: "Error 1172 occurred at Property Node (Arg :1) Error accessing property SolidWorks.Interop.sldworks.ISldWorks.ActiveDoc, (System.ArgumentNullException: Key cannot be null.
    Parameter name: key)"

    It's no matter if i load assembly from GAC or directly from project directory. Always the same.
    I've tried every idea i had.
    Can anyone help me with this?
    I enclose API (.net 4.0) for those, who want to help.
    Thanks a lot!
    Zyga

    SW_API.zip

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.