I don't think that the method you are referring works for all cameras. IP cameras delivers MPEG or similar stream, generally is used for survelliance. The URL for the stream depends from manufacured/model.
GigE is a standard for Machine Vision and gives you total control over the camera/acquisition process.
Anyway Basler uses Pylon Driver/Library wich is available on Basler website
After you are shure that your camera is reacheable from your pc (try a ping to the cam or use the pylon Viewer), there are 2 way to use the Pylon driver:
1st easy way is available for Windows (I don't know in linux)
Pylon driver installs a standard VFW interface so you can read your cam using cv::VideoCapture(camIdx)
where of camIdx
is the the id of capturing device assigned by your OS. If there is a single camera connected, (not even a webcam) just pass 0 else try to detect the id. Because might be difficult to locate the id
in your computer you could start with a searching loop like this
bool EnumerateCameras(std::vector<int> &camIdx)
{
std::string winName;
Mat frame;
std::cout << "Searching for cameras IDs...";
camIdx.clear();
for(int idx=0; idx<10; idx++)
{
VideoCapture cap(idx); // open the camera
if(cap.isOpened()) // check if we succeeded
{
camIdx.push_back(idx); // ad the ID to list of available cameras
std::cout << idx << "OK ";
cap >> frame;
winName = "A frame from camID: " + std::to_string(idx);
imshow(winName,frame); // display a frame from the current camera
}
}
cout << std::endl << camCnt << " cam(s) available";
cout "Press a key..."
cv::waitKey(0);
return (camIdx.size()>0); // returns success
}
2nd way is more powerful and gives you total control of camera features on Linux too
You have to use the Basler Pylon Camera Software Suite as library to grab the image from the cam. Once you have grabbed the image in Pylon you can map it to a cv::Mat
Pylon offers many different grabbing techniques (and many examples in C++).
Link the Pylon Lib to your OpenCV project and include needed Pylon function calls to catch a pylon::CGrabResultPtr
. Once you have the ptrGrabResul map it to a Mat as code below;
pylon::CGrabResultPtr ptrGrabResult;
cv::Mat theFrame;
//
// Use your preferred Pylon grabbing technique to obtain ptrGrabResult
//
// suppose your camera is monochrome... get a pointer to pylon image
const pylon::uint8_t *pImageBuffer = (uint8_t *)ptrGrabResult->GetBuffer();
int frameCols = ptrGrabResult->GetWidth();
int frameRows = ptrGrabResult->GetHeight();
// Map the pylon image buffer to a cv::Mat (create a cv::Mat from external buffer)
theFrame cv::Mat(cv::Size(frameCols, frameRows), CV_8U, (void*)pImageBuffer, cv::Mat::AUTO_STEP);
//
// Go on using OpenCV
// Take care to buffer life cycle because it's out of your control
// and it will be destroyed/changed on next grab
// in case keep a copy of it
cv::Mat myFrame;
theFrame.copyTo(myFrame); // myFrame life cycle is now under your control