Initialize NImage on heap C++

General information about Neurotechnology and its software

Initialize NImage on heap C++

Postby zyunting » Jan 29, 2019 04:49

Currently I am experimenting on using Async operation to hopefully speed up the process (by reading the image and processing at the same time)

The code is similar to this
Code: Select all
               
                for (int i=0; i < 3 ; i++)
                {

                        auto subject = new NSubject;
                        auto finger = new NFinger;

                        subject->GetFingers().Add(*finger);


                        subject->SetId(std::to_string(i));

                        // Auto Detecting pixel format. ex. NPF_GRAYSCALE_8U
                        auto finger_image = new NImage::FromFile(dir_prefix + file_list[i]);

                        if(finger_image->GetHorzResolution() != 500)
                        {
                                finger_image->SetHorzResolution(500);
                        }

                        if(finger_image->GetVertResolution() != 500)
                        {
                                finger_image->SetVertResolution(500);
                        }

                        finger->SetImage(finger_image);

                        NBiometricOperations operations = nboCreateTemplate;
                        if (biometricEngine.GetFingersCalculateNfiq()) operations = (NBiometricOperations)(operations | nboAssessQuality);
                        NBiometricTask biometricTask = biometricEngine.CreateTask(operations, *subject);
                        NAsyncOperation operation = biometricEngine.PerformTaskAsync(biometricTask);
                        operation.AddCompletedCallback(&CreateTemplateAsyncCompletedCallback, subject);
                }
                while(true)
                {
                        ;
                }


The allocated memory will be cleared somewhere else.
But for NImage, the compiler will throw me
Code: Select all
error: expected type-specifier
    auto finger_image = new NImage::FromFile(dir_prefix + file_list[i]);
                            ^~~~~~

Is there any ways to initialize NImage on the heap? Or is there any other approach to this?

Thanks!
zyunting
 
Posts: 12
Joined: Sep 29, 2018 01:52

Re: Initialize NImage on heap C++

Postby MartynasV » Jan 30, 2019 12:03

zyunting wrote:Currently I am experimenting on using Async operation to hopefully speed up the process (by reading the image and processing at the same time)

The code is similar to this
Code: Select all
               
                for (int i=0; i < 3 ; i++)
                {

                        auto subject = new NSubject;
                        auto finger = new NFinger;

                        subject->GetFingers().Add(*finger);


                        subject->SetId(std::to_string(i));

                        // Auto Detecting pixel format. ex. NPF_GRAYSCALE_8U
                        auto finger_image = new NImage::FromFile(dir_prefix + file_list[i]);

                        if(finger_image->GetHorzResolution() != 500)
                        {
                                finger_image->SetHorzResolution(500);
                        }

                        if(finger_image->GetVertResolution() != 500)
                        {
                                finger_image->SetVertResolution(500);
                        }

                        finger->SetImage(finger_image);

                        NBiometricOperations operations = nboCreateTemplate;
                        if (biometricEngine.GetFingersCalculateNfiq()) operations = (NBiometricOperations)(operations | nboAssessQuality);
                        NBiometricTask biometricTask = biometricEngine.CreateTask(operations, *subject);
                        NAsyncOperation operation = biometricEngine.PerformTaskAsync(biometricTask);
                        operation.AddCompletedCallback(&CreateTemplateAsyncCompletedCallback, subject);
                }
                while(true)
                {
                        ;
                }


The allocated memory will be cleared somewhere else.
But for NImage, the compiler will throw me
Code: Select all
error: expected type-specifier
    auto finger_image = new NImage::FromFile(dir_prefix + file_list[i]);
                            ^~~~~~

Is there any ways to initialize NImage on the heap? Or is there any other approach to this?

Thanks!

Hello,

You should initialize according to RAII(https://en.wikipedia.org/wiki/Resource_ ... ialization), as it is done in all our examples. It is good practice(easier memory management).
So just remove "new" keyword from "auto finger_image = NImage::FromFile(dir_prefix + file_list[i]);" line.
Martynas V
Neurotechnology
MartynasV
Neurotechnology
 
Posts: 498
Joined: Feb 27, 2015 11:24
Location: Vilnius, Lithuania


Return to Public

Who is online

Users browsing this forum: No registered users and 3 guests

cron