Ejemplo n.º 1
0
CPropertyItem_FullView::CPropertyItem_FullView(EdsImageRef	imageRef)
{
	EdsImageInfo info;
	char value[EDS_MAX_NAME] = {0};
	if( EDS_ERR_OK == EdsGetImageInfo( imageRef , kEdsImageSrc_RAWFullView , &info ) )
	{
		sprintf_s( value , EDS_MAX_NAME, "%dx%d %dbit" , info.width , info.height , info.componentDepth );
		m_value.push_back(value);
		strcpy_s(m_title, EDS_MAX_NAME, "FullView");
	}
}
void CanonCamera::UpdateView()
{

	if(!liveView)
		return;

    EdsError err = EDS_ERR_OK;
    EdsStreamRef stream = NULL;
    EdsEvfImageRef evfImage = NULL;

    // Create memory stream.
    err = EdsCreateMemoryStream(0, &stream);
  
	if(err != EDS_ERR_OK)
    {
        printf("Error in EdsCreateMemoryStream: 0x%X\n", err);
    }    

    err = EdsCreateEvfImageRef(stream, &evfImage);
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsCreateEvfImageRef: 0x%X\n", err);  
    }    

	
	bool wait = true;

    int numTries = 0;
    
	while(wait && numTries++ < 20)
    {
        err = EdsDownloadEvfImage(camera, evfImage);
        if(err != EDS_ERR_OK && err != EDS_ERR_OBJECT_NOTREADY)
        {
            printf("Error in EdsDownloadEvfImage: 0x%X\n", err);

        }
        if(err == EDS_ERR_OBJECT_NOTREADY)
        {
            Sleep(250);
        }
        else
        {
            wait = false;
        }
    }
    if(numTries > 20)
    {
        printf("ERROR: camera is taking too long for EdsDownloadEvfImage\n");

    }

    unsigned char* pByteImage = NULL;

    // Get image (JPEG) pointer.
    err = EdsGetPointer(stream, (EdsVoid**)&pByteImage );
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsGetPointer Histogram: 0x%X\n", err);
  
    }

    EdsUInt32 size;
    err = EdsGetLength(stream, &size);
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsGetLength Histogram: 0x%X\n", err);
 
    }

    EdsImageRef image = NULL;
    EdsImageInfo imageInfo;

    err = EdsCreateImageRef(stream, &image);
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsCreateImageRef: 0x%X\n", err);
 
    }

    err = EdsGetImageInfo(image, kEdsImageSrc_FullView, &imageInfo);
    if(err != EDS_ERR_OK)
    {
        printf("Error in EdsGetImageInfo: 0x%X\n", err);

    }

    if(imageInfo.componentDepth != 8)
    {
        printf("Error imageInfo.componentDepth != 8\n");

    }

	liveImage = cvCreateImage(cvSize(imageInfo.width, imageInfo.height), IPL_DEPTH_8U, imageInfo.numOfComponents);

    
    EdsUInt32 DataSize = 0;

    CImage cImage;
    HRESULT hr;

    CComPtr<IStream> iStream = NULL;
    HGLOBAL hMem = GlobalAlloc(GHND, size);
    LPVOID pBuff = GlobalLock(hMem);
    memcpy(pBuff, pByteImage, size);
    GlobalUnlock(hMem);
    hr = CreateStreamOnHGlobal(hMem, TRUE, &iStream);

    // Get the bitmap image from the stream
    if ((hr = cImage.Load(iStream)) == S_OK)
    {
        
        int pitch = cImage.GetPitch();
        int height = cImage.GetHeight();
        BYTE* pBits = (BYTE*)cImage.GetBits();
        if (pitch < 0)
            pBits += (pitch *(height -1));
        memcpy(liveImage->imageData, pBits, abs(pitch) * height);
		
    }

	cImage.~CImage();
    
    GlobalFree(hMem);
	

    cvFlip(liveImage, NULL, 0);

    // Release stream
    if(stream != NULL)
    {
        err = EdsRelease(stream);
        if(err != EDS_ERR_OK)
        {
            printf("Error in EdsRelease: 0x%X\n", err);

        }
        stream = NULL;
    }

   
   if(evfImage != NULL)
    {
        err = EdsRelease(evfImage);
        if(err != EDS_ERR_OK)
        {
            printf("Error in EdsRelease: 0x%X\n", err);

        }
        evfImage = NULL;
    }

	EdsRelease(image);
	
	cvShowImage(windowName.c_str(), liveImage);

	cvReleaseImage(&liveImage);
    
}
Ejemplo n.º 3
0
EdsError EDSCALLBACK CanonEDCamera::handleObjectEvent( EdsObjectEvent event, EdsBaseRef  object, EdsVoid * context) 
{ 
   printf ("Object Event triggered\n");

   CanonEDCamera* mmCanon = (CanonEDCamera*) g_Self;
  
   switch(event) 
   { 
      case kEdsObjectEvent_DirItemRequestTransfer: 
         {
            EdsError err = EDS_ERR_OK;
            EdsStreamRef stream = NULL;

            EdsDirectoryItemInfo dirItemInfo;
            err = EdsGetDirectoryItemInfo(object, &dirItemInfo);

            // do we need to notify the camera?
            /*
             if (err == EDS_ERR_OK)
             {
             CameraEvent e("DownloadStart");
             _model->notifyObservers(&e);
             }
             */

            if (err == EDS_ERR_OK)
            {
               //err = EdsCreateFileStream(dirItemInfo.szFileName, kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);
               err = EdsCreateMemoryStream(0, &stream);
            }

            // Set Progress Callback???

            // Download Image
            if (err == EDS_ERR_OK)
            {
               err = EdsDownload(object,  dirItemInfo.size, stream);
            }

            if (err == EDS_ERR_OK)
            {
               err = EdsDownloadComplete(object);
            }

            EdsImageRef imageRef = NULL;

            if (err == EDS_ERR_OK)
            {
               err = EdsCreateImageRef(stream, &imageRef);
            }

            EdsImageInfo imageInfo;

            if (err == EDS_ERR_OK)
            {
               err = EdsGetImageInfo(imageRef, kEdsImageSrc_FullView, &imageInfo);
            }
            if (err == EDS_ERR_OK)
            {
               printf ("Image Width: %d\n", imageInfo.width);
            }


         }
         break; 
        
         default: 
          
         break; 
      } 
    
 
   // Object must be released 
   if(object) 
   { 
      EdsRelease(object); 
   } 
} 
Ejemplo n.º 4
0
//////////////////////////////////////////////////////
/// A picture is acquired from the target EdsImageRef and an acquisition picture is registered into a drawing instance.
void CAFFrameDlg::LoadImage()
{
	/// The picture of a drawing instance is cleared.
	m_pDrawImage->Clear(0);
	if( m_ImageRef == NULL )
		return;

	EdsImageSource source = kEdsImageSrc_RAWThumbnail;
	EdsImageInfo imageInfo;
	EdsGetImageInfo( m_ImageRef , source, &imageInfo); 

	/// Demand size is adjusted so that an aspect ratio may not change.
	EdsSize viewSize;
	float ratio;
	viewSize.width = m_pDrawImage->GetWidth();
	viewSize.height = m_pDrawImage->GetHeight();
	if(imageInfo.effectiveRect.size.width>imageInfo.effectiveRect.size.height)
	{
		ratio = (float)imageInfo.effectiveRect.size.width / viewSize.width;
		if((EdsInt32)(imageInfo.effectiveRect.size.height/ratio) > viewSize.height)
			ratio = (float)imageInfo.effectiveRect.size.height / viewSize.height;
	}
	else
	{
		ratio = (float)imageInfo.effectiveRect.size.height / viewSize.height;
		if((EdsInt32)(imageInfo.effectiveRect.size.width/ratio) > viewSize.width)
			ratio = (float)imageInfo.effectiveRect.size.width / viewSize.width;	
	}
	EdsSize size;
	size.width = (EdsInt32)(imageInfo.effectiveRect.size.width/ratio);
	size.height = (EdsInt32)(imageInfo.effectiveRect.size.height/ratio);

	/// Creation of an output stream.
	EdsStreamRef DstStreamRef;
	EdsError err = EdsCreateMemoryStream( 0 , &DstStreamRef );

	/// A picture is acquired from EdsImageRef.
	err = EdsGetImage( m_ImageRef , source , kEdsTargetImageType_RGB , imageInfo.effectiveRect , size , DstStreamRef );
	if( err == EDS_ERR_OK )
	{
		/// The start address of the acquired picture is acquired.
		EdsVoid* pBuff;
		EdsGetPointer( DstStreamRef , &pBuff );
		/// A picture is updated to a drawing instance.
		m_pDrawImage->SetImage( size.width , size.height , pBuff );
	}
	else
	{
		AfxMessageBox("The error occurred with the EdsGetImage function.");
	}
	/// The output stream is released.
	EdsRelease(DstStreamRef);

	// FocusInfo
	EdsFocusInfo	focusInfo = {0};
	err= EdsGetPropertyData( m_ImageRef, kEdsPropID_FocusInfo , 0 , sizeof(focusInfo), &focusInfo );
	m_focusInfo = focusInfo;
	if(err == EDS_ERR_OK)
	{
		float xRatio = 1;
		float yRatio = 1;

		xRatio = (float)size.width/focusInfo.imageRect.size.width;
		yRatio = (float)size.height/focusInfo.imageRect.size.height;
		for(EdsUInt32 i = 0; i < focusInfo.pointNumber; i++)
		{
			m_focusInfo.focusPoint[i].rect.point.x = (EdsUInt32)(m_focusInfo.focusPoint[i].rect.point.x * xRatio);
			m_focusInfo.focusPoint[i].rect.point.y = (EdsUInt32)(m_focusInfo.focusPoint[i].rect.point.y * yRatio);
			m_focusInfo.focusPoint[i].rect.size.width = (EdsUInt32)(m_focusInfo.focusPoint[i].rect.size.width * xRatio);
			m_focusInfo.focusPoint[i].rect.size.height = (EdsUInt32)(m_focusInfo.focusPoint[i].rect.size.height * yRatio);
		}
		RedrawWindow();
	}
}