Ejemplo n.º 1
0
    EdsError Camera::requestDownloadEvfData( QImage& img )
    {
        if( !mIsLiveView ){
            std::cerr << "No live view" << std::endl;
            startLiveView();
            return EDS_ERR_OK;
        }
        
		
        EdsError err = EDS_ERR_OK;
        EdsStreamRef stream = NULL;
        EdsEvfImageRef evfImage = NULL;
        
        // Create memory stream.
		err = EdsCreateMemoryStream(0, &stream);
        
        // Create EvfImageRef.
        if(err == EDS_ERR_OK) {
			//std::cout << " memoryOK" << std::endl;
            err = EdsCreateEvfImageRef(stream, &evfImage);
        }
        
        // Download live view image data.
        if(err == EDS_ERR_OK){
			//std::cout << " dataOK" << std::endl;
            err = EdsDownloadEvfImage(mCamera, evfImage);
        }
        
        // Display image
        EdsUInt32 length;
        unsigned char* image_data;
        EdsGetLength( stream, &length );
        if( length <= 0 ) return EDS_ERR_OK;
        
        EdsGetPointer( stream, (EdsVoid**)&image_data );
		
		//std::cout << "length:" << length << " " << sizeof(image_data) << std::endl;
        // reserve memory
        img = QImage::fromData(image_data, length, "JPG");
	
        //    Buffer buffer( image_data, length );
        //    surface = Surface( loadImage( DataSourceBuffer::create(buffer), ImageSource::Options(), "jpg" ) );
        
        // Release stream
        if(stream != NULL) {
            EdsRelease(stream);
            stream = NULL;
        }
        // Release evfImage
        if(evfImage != NULL) {
            EdsRelease(evfImage);
            evfImage = NULL;
        }
        
        return EDS_ERR_OK;
    }
Ejemplo n.º 2
0
 void Camera::requestReadFile(const CameraFileRef& file, const std::function<void(EdsError error, QImage img)>& callback) {
    QImage img;
 
    EdsStreamRef stream = NULL;
    EdsError error = EdsCreateMemoryStream(0, &stream);
    if (error != EDS_ERR_OK) {
        std::cerr << "ERROR - failed to create memory stream" << std::endl;
        goto read_cleanup;
    }
 
    error = EdsDownload(file->mDirectoryItem, file->getSize(), stream);
    if (error != EDS_ERR_OK) {
        std::cerr << "ERROR - failed to download" << std::endl;
        goto read_cleanup;
    }
 
    error = EdsDownloadComplete(file->mDirectoryItem);
    if (error != EDS_ERR_OK) {
        std::cerr << "ERROR - failed to mark download as complete" << std::endl;
        goto read_cleanup;
    }
 
    unsigned char* data;
    error = EdsGetPointer(stream, (EdsVoid**)&data);
    if (error != EDS_ERR_OK) {
        std::cerr << "ERROR - failed to get pointer from stream" << std::endl;
        goto read_cleanup;
    }
 
    EdsUInt32 length;
    error = EdsGetLength(stream, &length);
    if (error != EDS_ERR_OK) {
        std::cerr << "ERROR - failed to get stream length" << std::endl;
        goto read_cleanup;
    }
 
    img = QImage::fromData(data, length, "JPG");
 
 read_cleanup:
    if (stream) {
        EdsRelease(stream);
    }
 
    callback(error, img);
 }
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.º 4
0
    //---------------------------------------------------------------------
    bool CanonCameraWrapper::grabPixelsFromLiveView(int rotateByNTimes90){
        EdsError err                = EDS_ERR_OK;
        EdsEvfImageRef evfImage     = NULL;
		EdsStreamRef stream         = NULL;
		EdsUInt32 bufferSize        = 2 * 1024 * 1024;

        bool success = false;

		if( evfMode == 0 ){
            printf("grabPixelsFromLiveView - live view needs to be enabled first\n");
            return false;
		}

		// Create memory stream.
		err = EdsCreateMemoryStream(bufferSize, &stream);

		// Create EvfImageRef.
		if (err == EDS_ERR_OK){
			err = EdsCreateEvfImageRef(stream, &evfImage);
		}

		// Download live view image data.
		if (err == EDS_ERR_OK){
			err = EdsDownloadEvfImage(theCamera, evfImage);
		}

        if (err == EDS_ERR_OK){
           // printf("Got live view frame %i \n", liveViewCurrentFrame);
            liveViewCurrentFrame++;

            EdsUInt32 length;
            EdsGetLength(stream, &length);

            if( length > 0 ){

                unsigned char * ImageData;
                EdsUInt32 DataSize = length;

                EdsGetPointer(stream,(EdsVoid**)&ImageData);
                EdsGetLength(stream, &DataSize);

                memoryImage convertor;
                if( convertor.loadFromMemory((int)DataSize, ImageData, rotateByNTimes90) ){

                    int imageWidth  = convertor.width;
                    int imageHeight = convertor.height;

                    if( imageWidth > 0 && imageHeight > 0 ){

                        if( livePixels == NULL || ( livePixelsWidth != imageWidth || livePixelsHeight != imageHeight ) ){
                            if( livePixels != NULL )delete[] livePixels;
                            livePixels          = new unsigned char[imageWidth * imageHeight * 3];
                            livePixelsWidth     = imageWidth;
                            livePixelsHeight    = imageHeight;
                        }

                        unsigned char * pix = convertor.getPixels();

                        int numToCopy = imageWidth * imageHeight * 3;
                        for(int i = 0; i < numToCopy; i++){
                            livePixels[i] = pix[i];
                        }

                        //printf("Live view frame converted to pixels\n");
                        success = true;

                    }else{
                        printf("unable to convert the memory stream! width and height 0 \n");
                    }
                }else{
                    printf("Unable to load from memory\n");
                }
            }
        }

        easyRelease(stream);
        easyRelease(evfImage);

		//Notification of error
		if(err != EDS_ERR_OK){
			if(err == EDS_ERR_OBJECT_NOTREADY){
			    printf("saveImageFromLiveView - not ready\n");
			}else if(err == EDS_ERR_DEVICE_BUSY){
                printf("saveImageFromLiveView - device is busy\n");
			}
            else{
                //printf("saveImageFromLiveView - some other error\n");
            }
            return false;
		}

		return success;
    }
Ejemplo n.º 5
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();
	}
}