Giter Club home page Giter Club logo

Comments (5)

TIS-Stefan avatar TIS-Stefan commented on June 30, 2024

Hello

I am sorry for my late answer.
From my understanding, you do not unpack the 12bit format correctly, but you simply uses 2 bytes per pixel. I suggest to use
"Polarized Mono 8" first and separate the incoming images with

void CreatePolarImages(int width, int height, _MyData *pData)
{
   if (!pData->mat_created)
   {
		int h = height / 2;
		int w = width / 2;
		for (int i = 0; i < 4; i++)
		{
			pData->grayImage[i].create( h, w, CV_8UC1);
			pData->colorImage[i].create(h , w, CV_8UC4);
			char WindowName[256];
			sprintf(WindowName, "Polarization %d", i + 1);
			cv::namedWindow(WindowName);
		}
		pData->mat_created = true;
	}
}

/////////////////////////////////////////////////////////////////////////
//
void AcquisitionCallback(ArvStream *pStream, void *pVoidData)
{
	_MyData *pMyData = (_MyData *)pVoidData;

	ArvBuffer *pBuffer = arv_stream_try_pop_buffer(pStream);

	if (pBuffer != NULL)
	{
		ArvBufferStatus Status = arv_buffer_get_status(pBuffer);
		if (Status == ARV_BUFFER_STATUS_SUCCESS)
		{
			pMyData->ImageReceived = true;

			int height = arv_buffer_get_image_height( pBuffer);
			int width = arv_buffer_get_image_width( pBuffer);

			
			pMyData->displayImage.create( height, width,
										   ArvPixelFormat2OpenCVType( pBuffer )
										   );

			size_t buffersize;										   
			const void* bytes = arv_buffer_get_data(pBuffer, &buffersize);
			memcpy( pMyData->displayImage.data, bytes, buffersize );

			if( strcmp(pMyData->displayWindowName,"") != 0)
			{
				cv::imshow(pMyData->displayWindowName, pMyData->displayImage);
				cv::waitKey(1);
			}
			CreatePolarImages(width,height, pMyData);

			unsigned char* sourcePixel = (unsigned char*)bytes;
			unsigned char* destPixel[4];

			for (int i = 0; i < 4; i++)
			{
				destPixel[i] = pMyData->grayImage[i].data;
			}

			for (int y = 0; y < height; y += 2)
			{
				for (int x = 0; x < width; x += 2)
				{
					*destPixel[1]++ = *sourcePixel++;
					*destPixel[0]++ = *sourcePixel++;
				}
				for (int x = 0; x < width; x += 2)
				{
					*destPixel[2]++ = *sourcePixel++;
					*destPixel[3]++ = *sourcePixel++;
				}
			}

			for (int i = 0; i < 4; i++)
			{
				cv::cvtColor(pMyData->grayImage[i], pMyData->colorImage[i], cv::COLOR_BayerRG2BGR);
			}

			ShowPolarImages(pMyData);
			

			arv_stream_push_buffer(pStream, pBuffer);
		}
		else
		{
            if( Status == ARV_BUFFER_STATUS_TIMEOUT)
            {
                pMyData->Packettimeouts++;
                //printf("Paket timeouts %d\n", pMyData->Packettimeouts);
            }
            else
			{
                printf("%s\n",getErrormessage(Status).c_str());
            }
            arv_stream_push_buffer(pStream, pBuffer);
			pMyData->error = true;
		}
	}
	else
	{
		printf("Buffer is null\n");
	}
}

If this works, you may change to 16 bits using the "Polarized Mono 16" format.

Stefan

from tiscamera.

jfai2023 avatar jfai2023 commented on June 30, 2024

Hi Stefan,

Thank you for your answer.

  1. More than half of the code in your example is missing. I was lucky to find the code zipped in an other issue.
  2. When compile with aravis-0.8 and OpenCV 4.6, the executable stay idle, and do nothing.

That said I was able to test, and adapt your code to work with PolarizedMono8 and PolarizedMono16.
Nonetheless I still want to use to PolarizedMono12Packed, what should I do to retrieve the information?

Thanks in advance.

Sincerely,
Julien Fleuret

from tiscamera.

TIS-Stefan avatar TIS-Stefan commented on June 30, 2024

Hello
I saw you also asked my US colleagues, who asked me too. However, I added the sample for Mono 8 at https://github.com/TheImagingSource/Linux-tiscamera-Programming-Samples/tree/master/cpp/Extract-four-images-from-polarization-camera. There should nothing missing.

12bit packed means, that 12bits make a pixel. Then immediately the next 12bits follow in the second byte of the first pixel. So you need to extract this stream.

You have 3 bytes for two pixels and split them accordingly. The idea could be:

p1 = (WORD)*data & 0xFFF0;
p1 = p1 >> 4;
pdata++;
p2 = (WORD)*data & 0x0FFF;

data is a BYTE* pointer to the image data.
But I did not try that on my own. If that does not work as expected, please let me know.

Best regards
Stefan

from tiscamera.

TIS-Stefan avatar TIS-Stefan commented on June 30, 2024

Hello Julien

I updated the above mentioned sample. It handles the mono 12bit packed and mono 16 bit video formats now. Unpacking of 12bits to 16bits is not that easy as I thought.

Stefan

from tiscamera.

jfai2023 avatar jfai2023 commented on June 30, 2024

Hi Stefan,

Thank you very much.
It helps a lot.

Sincerely,
Julien

from tiscamera.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.