OpenCV with remoteAPI

Typically: "How do I... ", "How can I... " questions
Post Reply
pluckz
Posts: 7
Joined: 19 Mar 2019, 12:58

OpenCV with remoteAPI

Post by pluckz » 08 Apr 2019, 11:13

Hello guys, does anyone know how can I transform the array return from function simxGetVisionSensorImage to a variable Mat?

Here is my current code:

Code: Select all

simxInt f, res;
	simxInt resolution[2];
	simxUChar *image;
	res=simxGetObjectHandle(clientID, "vision",&f,simx_opmode_oneshot_wait);
	if(res == simx_return_ok)
		cout << "Funcionou a camara" << endl;
	else {
		cout << "Não funcionou a camara" << endl;
	}
	int p = 0;
	simxGetVisionSensorImage(clientID, f, resolution, &image, 0, simx_opmode_streaming);
	while (simxGetConnectionId(clientID) != -1) // while we are connected to the server..
	{
		// Fetch the newest joint value from the inbox (func. returns immediately (non-blocking)):
		if (simxGetVisionSensorImage(clientID, f, resolution, &image, 0, simx_opmode_buffer) == simx_return_ok)
		{


			p = p + 1;
			if (p == 100) {
				break;
			}

			// here we have the newest joint position in variable jointPosition!    
		}
		else
		{
			// we landed in this code section, this does not always mean we have an error!!!
		}
	}
		
	Mat myMat;

	cv::Mat my_mat(resolution[0], resolution[1], CV_8UC1, &image); //in case of BGR image use CV_8UC3
	//myMat = convertToMat(image,800,600);
	namedWindow("window", CV_WINDOW_AUTOSIZE);
	imshow("window", my_mat);
	

Post Reply