how to load an image and convert it to PXCImage

how to load an image and convert it to PXCImage

imagem de JIANCHAO L. (Intel)

Could anyone tell me how load your own image from local machine instead of captured from camera, and convert it to PXCImage. thanks a lot

22 posts / 0 new
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.
imagem de Mikhail Nikolsky (Intel)

Nice to see first question on this forum:)

Use PXCSession::CreateAccelerator function to create accelerator instance (with type ACCEL_TYPE_CPU if your data located in general CPU memory), then PXCAccelerator::CreateImage to create PXCImage object:
pxcStatus PXCAccelerator::CreateImage(PXCImage::ImageInfo *info, PXCImage::ImageOption options, PXCImage::ImageData *data, PXCImage **image)=0;

The 'info' parameter is mandatory and should contain valid width, height and format.
The 'options' parameter is reserved, set to 0.
The 'data' parameter is optional:
1. If 'data' parameter specified, PXCImage object refer to external memory buffer provided by pointer(s) and pitch(es) in 'data' structure without any data copying.
2. If 'data' parameter not specified (data == NULL), PXCImage object allocates internal memory buffer(s) for image data. Use AcquireAccess+ReleaseAccess or CopyData functions to copy data from your buffer to PXCImage object.

Supposing you have image data in RGB24 color format under pointer


unsigned char *rgb_data;

int rgb_pitch; // bytes between image lines

here is code example for case 1:


    session->CreateAccelerator(PXCAccelerator::ACCEL_TYPE_CPU, accelerator);

    ...

    PXCImage::ImageInfo info;

    memset(&info, 0, sizeof(info));

    // fill info.width=...; info.height=...; info.format=PXCImage::COLOR_FORMAT_RGB24;

    PXCImage::ImageData data;

    memset(&data, 0, sizeof(data));

    data.format = PXCImage::COLOR_FORMAT_RGB24;

    data.planes[0] = rgb_data;

    data.pitches[0] = rgb_pitch;

    sts = accelerator->CreateImage(&info, 0, &data, &image);

code example for case 2 using AcquireAccess/ReleaseAccess functions:


    sts = accelerator->CreateImage(&info, 0, 0, &image);

    PXCImage::ImageData data;

    sts = image->AcquireAccess(PXCImage::ACCESS_WRITE, PXCImage::COLOR_FORMAT_RGB24, &data);

    for (int y = 0; y < info.height; y++)

    {

        memcpy(data.planes[0] + data.pitches[0]*y, rgb_data + rgb_pitch*y, 3*info.width);

    }

    sts = image->ReleaseAccess(&data);

and code example for case 2 using CopyData function:


    sts = accelerator->CreateImage(&info, 0, 0, &image);

    PXCImage::ImageData data;

    memset(&data, 0, sizeof(data));

    data.format = PXCImage::COLOR_FORMAT_RGB24;

    data.planes[0] = rgb_data;

    data.pitches[0] = rgb_pitch;

    PXCImage *source_image = 0;

    sts = accelerator->CreateImage(&info, 0, &data, &source_image);

    sts = image->CopyData(source_image);

    source_image->Release();

Error checking (sts >= PXC_STATUS_NO_ERROR) omitted in these examples for simplicity.

Note that in case 1 life-cycle of PXCImage object should be longer than life-cycle of rgb_data memory buffer meaning that you can’t destroy rgb_data buffer earlier than deletion of PXCImage object. Otherwise PXCImage may try to access invalid (destroyed) external buffer.

Please let us know if that helped or any other questions/issues.
You can also find description of mentioned and other API functions in %PCSDK_DIR%\doc\sdkmanual-core.pdf file.
Thanks.

imagem de JIANCHAO L. (Intel)

Thanks very much, it works!

imagem de JIANCHAO L. (Intel)

Hi, Mikhail

When I tried AcquireAccess to access the image data from one frame of the camera pipeline in Face Detection Sample, I used the following code patch:


sts = capture.ReadStreamAsync(images,&sps[0]);

PXCImage::ImageData data;

pxcStatus sts = images[0]->AcquireAccess(PXCImage::ACCESS_READ, PXCImage::COLOR_FORMAT_RGB24, &data);


I found that data had not been filled when the third line finished, the pitches and planes were both invalid. I'm quite confused. Can you tell me what have I missed that code? Thanks very much!

imagem de sudharson s.

while reading face detection code,it accept input from camera and passing camera recorded file as the input for processing the image...what we need to bypass camera and how to give downloaded image as the input to process the face detection..

Anexos: 

AnexoTamanho
Download face-detection.cpp3.6 KB
imagem de Mikhail Nikolsky (Intel)

JIANCHAO,

Many time-consuming functions designed in asynchronous model so that SDK can internally parallelize them into several CPU threads or offload to GPU. Such functions typically have Async suffix in the name and return PXCSheduler::SyncPoint object in last parameter for synchronization. If application wants to access output data, it should first call sp->Synchronize() to make sure operation completed and output data is valid. If application passes data to next component (ex, from camera to face or finger tracking), it may do it not waiting for intermediate sync point for better parallelization and performance (thanks to data dependency mechanism inside SDK). You can also find more details in sdkmanual-core document.
Specifically in your case, you need to sps[0]->Synchronize() before images[0]->AcquireAccess().

imagem de JIANCHAO L. (Intel)

Quote:

sudharson s. wrote:

while reading face detection code,it accept input from camera and passing camera recorded file as the input for processing the image...what we need to bypass camera and how to give downloaded image as the input to process the face detection..



//this line is for capturing images from camera

 sts = capture.ReadStreamAsync(images, &sps[0]);

//this line is for process, in order to bypass camera you need to input your downloaded image to ProcessImageAsync function

 sts=faceAnalyzer->ProcessImageAsync(images, &sps[1]);


the following code is for converting your own downloaded image to PXCImage:

void LoadImageFromLocal(PXCSession* session, PXCImage **dst_img, const char * path){
	IplImage *image = cvLoadImage(path);

	unsigned char *rgb_data;

	int rgb_pitch = image->widthStep; // bytes between image lines

	rgb_data = (unsigned char*)image->imageData;

	PXCAccelerator * accelerator;

	session->CreateAccelerator(PXCAccelerator::ACCEL_TYPE_CPU, &accelerator);

	PXCImage::ImageInfo info;

	memset(&info, 0, sizeof(info));

	info.height = image->height;

	info.width = image->width;

	info.format = PXCImage::COLOR_FORMAT_RGB24;

	PXCImage::ImageData data;

	memset(&data, 0, sizeof(data));

	data.format = PXCImage::COLOR_FORMAT_RGB24;

	data.planes[0] = rgb_data;

	data.pitches[0] = rgb_pitch;
	pxcStatus sts = accelerator->CreateImage(&info, 0, &data, dst_img);

}

imagem de sudharson s.

JIANCHAO,

1,queryface function is failed in our code eventhough we successfully process the image using ProcessImageAsync.
2.whether we need to pass rgb data for our downloaded image or bgr data is ok
3.how to synchronize the sp...since we are not using any camera for capturing image

whether insufficient hardware requirement is the reason for failure of query face function

can u tell the hardware requirements for processing the face detection sample...

imagem de JIANCHAO L. (Intel)

Quote:

sudharson s. wrote:

JIANCHAO,

1,queryface function is failed in our code eventhough we successfully process the image using ProcessImageAsync.
2.whether we need to pass rgb data for our downloaded image or bgr data is ok
3.how to synchronize the sp...since we are not using any camera for capturing image

whether insufficient hardware requirement is the reason for failure of query face function

can u tell the hardware requirements for processing the face detection sample...


Hi, sudharson s
First of all, you should check whether you have converted the image to PXCImage, and then make sure the face detect profile is set(refer to Face Recognition thread I posted);
Second, we need to pass rgb data as I've written in LoadImageFromLocal function where I use OpenCV to load image and fill PXCImage::ImageData.planes[0] with IplImage's imageData;
Third, Mikhail Nikolsky said "Many time-consuming functions designed in asynchronous model so that SDK can internally parallelize them into several CPU"threads or offload to GPU. ", I think this is the reason for using Synchronize() even when not using camera.

	PXCSmartSP sp;

	faceAnalyzer->ProcessImageAsync(&image, &sp);

	sp->Synchronize();

Good Luck!
Any problems you can refer to Mikhail Nikolsky.

imagem de Sri Ram K.

Hi Jianchao / Mikhail ,

Am working on gesture Recognition, trying to bypass the camera and identify the gesture from a single image.
Am giving input ,a depth image(Format - bitmap) and converted that into PXC Image.

1. Will the depth details are available in the converted PXC Image.
2. I want to Process this single image and get the blob image and data out of it using Processimageasync. whether it is possible?

Thanks in Advance...

imagem de sudharson s.

Hi JIANCHAO,
The code is working now...Thanks for your support..
What changes i need to do for smile detection..

imagem de JIANCHAO L. (Intel)

Quote:

sudharson s. wrote:

Hi JIANCHAO,
The code is working now...Thanks for your support..
What changes i need to do for smile detection..


Sorry for the delay, cuz I'm an intern and not a full time employee, you can try the following code to detect smiling.
Smiling, gender, age .etc are all in PXCFaceAnalysis::Attribute

			PXCFaceAnalysis::Attribute *attr = faceAnalyzer->DynamicCast();

			PXCFaceAnalysis::Attribute::ProfileInfo attrInfo;

			attr->SetProfile(PXCFaceAnalysis::Attribute::LABEL_EMOTION, &attrInfo);

imagem de sudharson s.

Hi JIANCHAO,
smile detection code is not working properly.it setting the same threshold value for all the images and i dont know whether i need to compare with threshold value or compare with the value 0.

imagem de JIANCHAO L. (Intel)

Quote:

sudharson s. wrote:

Hi JIANCHAO,
smile detection code is not working properly.it setting the same threshold value for all the images and i dont know whether i need to compare with threshold value or compare with the value 0.

Compare with value 0 would correct.

imagem de sudharson s.

HI JIANCHAO
QUERY DATA FUNCTION IN FACIAL ATTRIBUTE MODULE IS GETTING FAILED.SO IT IS NOT UPDATING THE SCORE VALUE OF THE GIVEN LABEL.

imagem de sudharson s.

HI JIANCHAO
QUERY DATA FUNCTION IN FACIAL ATTRIBUTE MODULE IS GETTING FAILED.SO IT IS NOT UPDATING THE SCORE VALUE OF THE GIVEN LABEL.

imagem de yuxiang z.

see

imagem de sudharson s.

HI JIANCHAO\MIKHAIL NIKOLSKY

QUERYDATA function in facial attribute is getting failed in my code.and its printing error code -3.

PXCFaceAnalysis::Attribute *attr = face->DynamicCast();

if (!attr) {
wprintf_s(L"Failed to locate the face attribute interface\n");

}

sts= attr->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_EMOTION,fidx,&attrInfo);
if (sts wprintf_s(L"Failed to query profile\n");
printf("%d\n",sts);
}

sts=attr->SetProfile(PXCFaceAnalysis::Attribute::LABEL_EMOTION,&attrInfo);
if (sts wprintf_s(L"Failed to set profile\n");
printf("%d\n",sts);
}

sts=attr->QueryData(PXCFaceAnalysis::Attribute::LABEL_EMOTION,fid,smile);
if (sts wprintf_s(L"Failed to query data\n");
printf("%d\n",sts);
}

printf("%d\n",attrInfo.threshold);
//for detecting smile

printf("the score value is %d\n",smile[0]);

if (sts wprintf_s(L"Failed to query data\n");
printf("%d\n",sts);
}

//if (smile[PXCFaceAnalysis::Attribute::INDEX_EMOTION_SMILE]>attrInfo.threshold)

if ( smile[0]>attrInfo.threshold ) {
printf("face fid smiled\n");
}
else
{
printf("face fid not yet smile\n");
}

imagem de sudharson s.

smile detection code working if the camera is available.But if camera is not availabe and if we give manually smiling face image,the query data function of smile attributes is failing eventhough we successfully query the face.so for smile detection we need to input video images.how to make the code work with still images

imagem de Muhammad Adeel Tampere university of Tec W.

Hi Everyone,

       I am working on Face Detection, I am pretty impressed by the Efficiency of the detector in IPC SDK.
But I found that It detectes the face which have only Inplane rotations & does not work with Out of Plane Rotation, I tried to solve it by changing the VeiwAngle in Detection class as VEIW_ROLL_30,VEIW_ROLL_30N ,VEIW_ROLL_60 ,VEIW_ROLL_60N were commented in the source code. Infact, I tried to set the Veiwangles manually aswell.
I only kept the VEIW_ANGLE_FRONTAL , But It detects more than frontal.

Let me know about solving this Problem, I want a detector with Both Inplane and Outplane detection .

imagem de fh i.

here is a vb method you can use to load image from local machine. but i am not sure whether it may help you. please have a try.

imagem de Mary K.

Quote:

JIANCHAO L. (Intel) wrote:

Quote:

sudharson s. wrote:

while reading face detection code,it accept input from camera and passing camera recorded file as the input for processing the image...what we need to bypass camera and how to give downloaded image as the input to process the face detection..

 

 


//this line is for capturing images from camera

 sts = capture.ReadStreamAsync(images, &sps[0]);

//this line is for process, in order to bypass camera you need to input your downloaded image to ProcessImageAsync function

 sts=faceAnalyzer->ProcessImageAsync(images, &sps[1]);

the following code is for converting your own downloaded image to PXCImage:

 

 


void LoadImageFromLocal(PXCSession* session, PXCImage **dst_img, const char * path){
	IplImage *image = cvLoadImage(path);

	unsigned char *rgb_data;

	int rgb_pitch = image->widthStep; // bytes between image lines

	rgb_data = (unsigned char*)image->imageData;

	PXCAccelerator * accelerator;

	session->CreateAccelerator(PXCAccelerator::ACCEL_TYPE_CPU, &accelerator);

	PXCImage::ImageInfo info;

	memset(&info, 0, sizeof(info));

	info.height = image->height;

	info.width = image->width;

	info.format = PXCImage::COLOR_FORMAT_RGB24;

	PXCImage::ImageData data;

	memset(&data, 0, sizeof(data));

	data.format = PXCImage::COLOR_FORMAT_RGB24;

	data.planes[0] = rgb_data;

	data.pitches[0] = rgb_pitch;
	pxcStatus sts = accelerator->CreateImage(&info, 0, &data, dst_img);

}

I try to run this code and "dst_image" is empty in result, but "info" and "data" contain correct data.

Faça login para deixar um comentário.