COleClientItem::CreateFromFile() is strange on Windows11 but is OK on Windows10 - c++

I got a strange result when executed the next code:
BOOL ret = pOleClientItem->CreateFromFile("a-bitmap-file.bmp");
On Windows11 but it is OK on Windows10 (pOleClientItem is a pointer to COleClientItem instance object).
The return code is TRUE, but that object's surface is not correctly drawn (on Windows11).
I tried the following,
I tried .png file instead .bmp file, and got a same result.
I tried CreateFromClipboard(), and got a same result.
a-bitmap-file.bmp is full-path.
a-bitmap-file.bmp is set security policy as full-control.

Related

Qt program using Matlab dll, Initialized successfully in local disk, but failed in My U disk

I am writing a Qt program using matlab dll, the matlab function is very simple, However I encountered some exception caused by initializing problem. So I have changed my part of code as below.
void DicomViewer::on_pushButton_clicked()
{
if(libMyAddInitialize()){
mwArray dicomArray2=Mat2mwArray(dicomMat1);
//c_matlab(1,dicomArray2,Mat2mwArray(dicomMat1));
mwArry2Mat(dicomArray2).copyTo(dicomMat2);
dicomImgShow(TEMPDICOM2);
libMyAddTerminate();
}
}
This part of the code provides a button to change my cv::Mat data. I am using two functions Mat2mwArrayandmwArray2Mat to convert Mat between mwArray. Funciton dicomImgShow is to show the Mat to My program. That I think code is not the key problem.
My Key problem is The button function only work in my local disk (C:/ and D:/). I put it into my U disk and it failed. I also tried to run it in admin mode, but failed again. So I wonder what's wrong in my program.
Thanks for anyone who come to help .

libpng warning in python opencv2

I managed to install and successfully import cv2 on a linux(Debian) virtual machine, using python 2.7. I tried to take a picture using my webcam with the following piece of code:
import cv2
from datetime import datetime
tar_file = datetime.now().strftime("%Y%m%d-%H%M%S") + '.png'
camera_port = 0
ramp_frames = 30
camera = cv2.VideoCapture(camera_port)
def get_image():
retval, im = camera.read()
return im
for i in xrange(ramp_frames):
temp = get_image()
camera_capture = get_image()
cv2.imwrite(tar_file, camera_capture)
camera = None
I have tested the code earlier on my windows 10 host machine and it works fine. When using this code the program successfully saves the file, but the file cannot be opened and the following error is displayed in the terminal:
libpng warning: Image width is zero in IHDR
libpng warning: Image height is zero in IHDR
libpng error: Invalid IHDR data
The error occurs as the camera_capture object is a NoneType, why is this so?
How can I prevent this error from happening and successfully take a snapshot through my webcam?
Edit : The error appears the occur when the line "cv2.imwrite(tar_file, camera_capture)" is run. Upon further inspection the camera_capture variable is a NoneType and the retval value is False which would explain the width and height being 0. Why is the variable a NoneType and how can I prevent this from happening?
The code is failing due to no data being written to the file. This causes the file to be empty and thus it cannot be opened. The reason the data returned is empty is most likely due to an incorrectly configured webcam. The solution to this is to connect the VM to the camera. If it still fails, try to install a driver on the VM for the webcam.

Cocos2dx Update and Thread 1: EXC_BAD_ACCESS

After updating Cocos2dx and Xcode I started receiving the error: Thread1:EXC_BAD_ACCESS (code=1, address=0x0). It happens when I set the position but I think it has to do with the png image:
auto backgroundSprite=Sprite::create("thing.png");
backgroundSprite->setPosition(Vec2(visibleSize.width /2 +origin.x,visibleSize.height / 2 + origin.y));
I have tried to add this code and image to a different project and it works fine. I have also tried to switch the image file to something else but it didn't work.
If you're running on desktop, make sure that Target Membership is checked for your thing.png and also check form Xcode IDE, file is available in Resource.
Go to build settings and set: Remove Text Metadata From PNG Files = No
Looks like you've got nullptr as backgroundSprite. Check it before calling setPosition.

SDL_RenderCopy() has strange behavior on Raspberry PI

This is driving me up the wall..
I've got a very simple SDL2 program.
It has a array of 3 SDL_Texture pointers.
These textures are filled as follows:
SDL_Texture *myarray[15];
SDL_Surface *surface;
for(int i=0;i<3;i++)
{
char filename[] = "X.bmp";
filename[0] = i + '0';
surface = SDL_LoadBMP(filename);
myarray[i] = SDL_CreateTextureFromSurface(myrenderer,surface);
SDL_FreeSurface(surface);
}
This works, no errors.
In the main loop (which is just a standard event loop waiting for SDL_QUIT, keystrokes and a user-event which a SDL_Timer puts in the event queue every second) I just do (for the timer triggered event):
idx = (idx+1) % 3; // idx is global var initially 0.
SDL_RenderClear(myrenderer);
SDL_RenderCopy(myrenderer, myarray[idx], NULL, NULL);
SDL_RendererPresent(myrenderer);
This works fine for 0.bmp and 1.bmp, but the 3rd image (2.bmp) simply shows as a black field.
This is structural.
If I alternate the first 2 images they are both fine.
If I alternate the 2nd and 3rd image the 3rd image doesn't show.
If I use more than 3 images then 3 and upwards show as black.
Loading order doesn't matter. It starts going wrong with the 3rd image loaded from disk.
All images are properly formatted BMP's.
I even saved 2.bmp back to disk under a different name by using SDL_SaveBMP() after it was loaded to make sure it got loaded in memory OK. The new file is bit for bit identical to the original.
This program, without modifications and the same bmp files, works fine on OSX (XCode5) and Windows (VC++ 2012 Express).
The problem only shows on the Raspberry PI.
I have placed explicit error checks on every call that can leave a result/error-code (not shown in the samples above for brevity) but all of them show "no error".
I have used the latest stable source set of www.libsdl.org and compiled as instructed (configure, make, make install, etc.).
Anybody got any idea what could be going on ?
P.S.
Keyboard input doesn't seem to work either on my PI, but I haven't delved into that yet.
Answering myself as I finally figured it out myself...
I finally went back to the README-raspberrypi.txt that came with the SDL2 sources.
I didn't read it carefully enough the first time around...
Problem 1: I'am running on a FULL-HD display. The PI's default GPU memory is 64MB which is not enough for large displays and double-buffering. As suggested in the README I increased this to 128MB and this solved the black image problem.
Problem 2: Text input wasn't working because my user-account was not in the input group. I had added the default "pi" account to the input group initially, but when I later started using another account I forgot to add that user to the group.
In short: Caught by my own (too) quick skimming of the documentation.

How do I guard against failure of cvLoad?

I am writing a program that uses OpenCV and involves intrinsic and distortion parameters. These parameters are loaded from .xml files saved on disc. I use the following commands in my opening declarations to load the files:
CvMat *intrinsic = (CvMat*)cvLoad("Intrinsics.xml");
CvMat *distortion = (CvMat*)cvLoad("Distortion.xml");
This works fine as long as the files are in the program's working directory. When they are not, the program crashes without any indication of the nature of the error. I have made the mistake of not having the xml files located correctly multiple times before, and I would like to make this easier to troubleshoot in the future.
I would like to create a guard against the files failing to load. Perhaps if they are not present my program could display an error message and exit gracefully. I saw the method suggested here, and it should work for me, but I was wondering if there was a cleaner way to do it without including another header.
For example, the OpenCV function cvQueryFrame returns 0 if it does not return a frame. I use the code
frame = cvQueryFrame(capture);
if(!frame)
{
printf("ERROR: Could not get frame from webcam.");
exit(-1);
}
to exit the program if cvQueryFrame fails to return a frame. I would like to do something similar with my matrix loading commands. Is this possible, and if so, how should I do it?
I checked the OpenCV documentation and could not find a description of cvLoad's behaviour when it cannot find the file specified so I am not sure how to proceed.
I am writing this project in C++ and running it on Windows 7.
It works. Go ahead and try it yourself:
CvMat *distortion = (CvMat*)cvLoad("Distortion.xml");
if (!distortion)
{
printf("!!! cvLoad failed");
exit(-1);
}