ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 How can i use Imageen Comp. With Hikrobot Camera
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

nuheroglu

Turkey
4 Posts

Posted - Apr 01 2023 :  18:05:28  Show Profile  Reply
Hello
I am using a camera. The SDK of the camera is in this link. 'https://www.hikrobotics.com/en/machinevision/service/download?module=0' This camera has its own SDK and DLL file. According to this SDK file, the image of this camera can be viewed as 'MV_CC_OpenDevice(Var handle: Pointer; nAccessMode : DWORD=1; nSwitchoverKey:Word=0):Integer; stdcall; external 'MvCameraControl.dll';
function '

'var handle: Pointer;' I can assign it to the Handle property of the component I defined in this section, for example

handle := ImageEn1.Handle;

Of course, this naturally doesn't quite work for me. What I want to do is to assign the ImageEn1.IO.Bitmap property of the camera image. Can you help me with this?
Thank you

nsmuhendislik

xequte

38608 Posts

Posted - Apr 02 2023 :  14:20:27  Show Profile  Reply
Hi

That does not look like the right API call. Do they have any code showing how to use it with TImage or TBitmap?



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

nuheroglu

Turkey
4 Posts

Posted - Apr 02 2023 :  14:27:50  Show Profile  Reply
There is a sample code for saving BMP image format from the camera's SDK. This code is as follows. However, this process takes an average of 2-3 seconds.

//Click Save BMP button
procedure TForm1.SAVE_BMP_BUTTONClick(Sender: TObject);
begin
  m_nSaveImageType := MV_Image_Bmp;
  m_nRet := SaveImage();
  if m_nRet<>MV_OK then
  begin
    ShowMessage( 'Save bmp fail.' + IntToHex(m_nRet,8) );
    exit
  end;
  ShowMessage( 'Save bmp succeed.' );
end;

//Save Image
function TForm1.SaveImage(): Integer;
Var
  nRecvBufSize: Cardinal;
  stImageInfo: MV_FRAME_OUT_INFO_EX;
  stParam: MV_SAVE_IMAGE_PARAM_EX;
  chImageName: String;  //ImageName
  hFile: THandle; //handle of the imageFile
  dwWriteLen: Cardinal; //Length that was written in the imageFile

begin
  if not m_bStartGrabbing then
  begin
    Result := MV_E_CALLORDER;
    exit
  end;

  //SaveImageType whether supported
  if not ((MV_Image_Bmp=m_nSaveImageType) or (MV_Image_Jpeg=m_nSaveImageType)) then
  begin
    Result := MV_E_SUPPORT;
    exit
  end;

  nRecvBufSize := 0;
  if Nil = m_pBufForDriver then
  begin
     //Get size of one frame from camera
     Result := GetIntValue(m_hDevHandle, 'PayloadSize', @nRecvBufSize);
     if Result<>MV_OK then
     begin
       ShowMessage( 'failed in get PayloadSize.' + IntToHex(Result,8) );
       exit
     end;
     m_nBufSizeForDriver := nRecvBufSize;
     m_pBufForDriver := AnsiStrAlloc(m_nBufSizeForDriver);
     if (Nil=m_pBufForDriver) or (not(StrBufSize(m_pBufForDriver)>0)) then
     begin
       ShowMessage( 'malloc m_pBufForDriver failed, run out of memory.' + IntToStr(m_nBufSizeForDriver) );
       exit
     end;
   end;

   //Start get one frame
   ZeroMemory(@stImageInfo, sizeof(MV_FRAME_OUT_INFO_EX));
   Result := MV_CC_GetOneFrameTimeout(m_hDevHandle^, m_pBufForDriver, m_nBufSizeForDriver, @stImageInfo, 1000);
   if Result=MV_OK then
   begin
     if Nil = m_pBufForSaveImage then
     begin
       // en:BMP image size: width * height * 3 + 2048 (Reserved BMP header size)
       m_nBufSizeForSaveImage := stImageInfo.nWidth * stImageInfo.nHeight * 3 + 2048;
       m_pBufForSaveImage := AnsiStrAlloc(m_nBufSizeForSaveImage);
       if (Nil=m_pBufForSaveImage) or (not(StrBufSize(m_pBufForSaveImage)>0)) then
       begin
         ShowMessage( 'malloc m_pBufForSaveImage failed, run out of memory.' + IntToStr(m_nBufSizeForSaveImage) );
         exit
       end;
     end;

     //Set camera parameter
     ZeroMemory(@stParam, sizeof(MV_SAVE_IMAGE_PARAM_EX));
     stParam.enImageType := m_nSaveImageType; //Image format to save
     stParam.enPixelType := stImageInfo.enPixelType;  //Camera pixel type
     stParam.nWidth := stImageInfo.nWidth;         //Width
     stParam.nHeight := stImageInfo.nHeight;          //Height
     stParam.nDataLen := stImageInfo.nFrameLen;
     stParam.pData := m_pBufForDriver;
     stParam.pImageBuffer := m_pBufForSaveImage;
     stParam.nBufferSize := m_nBufSizeForSaveImage;  //Buffer node size
     stParam.nJpgQuality := 80;
                                                //jpg encoding, only valid when saving as Jpg. SDK ignore this parameter when saving as BMP
     Result := MV_CC_SaveImageEx2(m_hDevHandle^, @stParam);
     if Result<>MV_OK then exit;

     //Save imageFile
     if MV_Image_Bmp=stParam.enImageType then
     begin
       chImageName := FormatCName('%s%d%s%d%s%03d%s', 'Image_w', stImageInfo.nWidth, '_h', stImageInfo.nHeight, '_fn', stImageInfo.nFrameNum, '.bmp');
     end
     else if True then
          begin
            chImageName := FormatCName('%s%d%s%d%s%03d%s', 'Image_w', stImageInfo.nWidth, '_h', stImageInfo.nHeight, '_fn', stImageInfo.nFrameNum, '.jpg');
          end
          else
          begin
            Result := MV_E_SUPPORT;
          end;
     hFile:= CreateFileA(PAnsiChar(AnsiString(chImageName)), GENERIC_READ or GENERIC_WRITE,
                         FILE_SHARE_READ or FILE_SHARE_WRITE, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
     if hFile = 0 then exit;
     WriteFile(hFile, m_pBufForSaveImage^, stParam.nImageLen, dwWriteLen, nil);
     CloseHandle(hFile);

  end;

  Result := MV_OK;
end;


nsmuhendislik
Go to Top of Page

xequte

38608 Posts

Posted - Apr 03 2023 :  18:58:53  Show Profile  Reply
Hi

If you are looking to display the frames of the camera, you can load from the buffer that the API provides using:

ImageEnView1.IO.LoadFromBuffer(...);

http://www.imageen.com/help/TImageEnIO.LoadFromBuffer.html

Alternatively, you can always just assign a TBitmap, using ImageEnView1.Assign( bmp );

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: