Issue with multiple imwrite(".pgm") format in loop
While saving an image capture as PGM format in a loop, the opencv library crashes on second iteration. The function which crashes is imwrite("out.pgm", gray_image, compression_params). Is there a workaround to solve this?
Thanks Deepth
Are you saving the image with same name in all iterations? It may cause problems if trying to overwrite an existing file. Moreover, why would you want to overwrite a file inside a loop? You'll end up with only the last image
Thank you Lorena for the quick reply. Yes I am overwriting the image in every iteration. It is a limitation with third party application, which access the image with same name and process it.
for ( unsigned int i = 0; i < loops; ++i ) bS = cap.read(frame);
}
@deepthpk what are you using as compression_params? Have you tried without them? Do you really need them?
I tried compression_params.push_back(CV_IMWRITE_PXM_BINARY); compression_params.push_back(1); both 1 and 0. Doesnt make a difference in crash
Problem is probably in that "push_back". Why don't you just try
imwrite("sample.pgm", gray_image);
and see if it works? Then if you really need to specify the flags for any reason, we'll work about itwhen i removed the compression_params as you mentioned, the program crashed on first iteration itself! imwrite("sample.pgm", gray_image);
Interesting... I guess you've manually compile OpenCV with CMake and enabled the world dll. Are you really using it? I don't know a lot about the dll's, maybe someone else can help here
No, i just took the library as it is. I didnt compile. The error occurs in the function call to opencv_world300.dll. But thanks a lot for looking into this!
But still what do you think the issue can be, if its not the issue about dll. I have extra information: If u save the out file with PNG format,then the crash never happens in any iteration. The issue exists only in PGM format. Unfortunately the thrid party application only takes pgm format.