con:live_dump_start(dumpfile)con:live_get_frame(what)con:live_dump_frame()
frame_header = numpy.dtype([('magic','int32'),('header_size', 'int32'),('version_major', 'int32'),('version_minor','int32')])frame_length = numpy.dtype([('length','int32')])myFile = open('file.lvdump','r')header=numpy.fromfile(myFile, dtype=frame_header, count=1)length=numpy.fromfile(myFile, dtype=numpy.uint32, count=1)frame=numpy.fromfile(myFile, dtype=numpy.ubyte, count=length)myFile.close()
First of all, to get a frame I am using the Lua code:Code: [Select]con:live_dump_start(dumpfile)con:live_get_frame(what)con:live_dump_frame()
Already here I have some question. If I change the "what" I get different file size but from the lvdump function it seems that "what" should be 0=noframe; 1=vp; 5=vp+bm; 13=vp+bm+pal; 29=vp+bm+pal+bmo in all these cases the size should be width x height x bpp but the fact that I superimpose bm or not it shouldn't affect it.
local frame = con:get_live_data(nil, 1)local pimg = liveimg.get_viewport_pimg(nil, frame, skip)local lb = pimg:to_lbuf_packed_rgb(nil)
I know there are different methods, actually my first lua code wasCode: [Select]local frame = con:get_live_data(nil, 1)local pimg = liveimg.get_viewport_pimg(nil, frame, skip)local lb = pimg:to_lbuf_packed_rgb(nil)
$ chdkptp -c -iconnected: Canon PowerShot ELPH 130 IS, max packet size 512con> !frame = con:get_live_data(nil, 1)con> !return frame="userdata: 04CEFD30"con> !pimg = liveimg.get_viewport_pimg(nil, frame, false)con> !return pimg="userdata: 04CB8958"con> !lb = pimg:to_lbuf_packed_rgb(nil)con> !fh=io.open('test.rgb','wb') lb:fwrite(fh) fh:close()
I know that it works because when I run the lvdumping I obtain the netbpm file and if I run chdkptp with the gui I can start the live view, so chdk works, the camera works and the decoding seems to work. It seems that I am the only part of this problem not working correctly.
cli:execute('lvdumpimg -vp=file.ppm')
That seems like it should work. I did the following in chdkptp CLI and was able to load the resulting test.rgb in gimp as raw image data (720x480 rgb for this camera)Code: [Select]$ chdkptp -c -iconnected: Canon PowerShot ELPH 130 IS, max packet size 512con> !frame = con:get_live_data(nil, 1)con> !return frame="userdata: 04CEFD30"con> !pimg = liveimg.get_viewport_pimg(nil, frame, false)con> !return pimg="userdata: 04CB8958"con> !lb = pimg:to_lbuf_packed_rgb(nil)con> !fh=io.open('test.rgb','wb') lb:fwrite(fh) fh:close()
What model of camera are you using?
Are you using the official chdkptp distribution (if so, what version and platform?), or one of the python interfaces?
If you are looking for RGB output to analyze, is there a reason not to just do Code: [Select]cli:execute('lvdumpimg -vp=file.ppm')and load file.ppm in your python code?
import matplotlib.pyplot as pltimport numpyimport cv2fb_type = {0:12, # LV_FB_YUV8 8 bit per element UYVYYY, used for live view 1:8, # LV_FB_PAL8 8 bit paletted, used for bitmap overlay. Note palette data and type sent separately 2:16, # LV_FB_YUV8B 8 bit per element UYVY, used for live view and overlay on Digic 6 3:16, # LV_FB_YUV8C 8 bit per element UYVY, used for alternate Digic 6 live view 4:8 # LV_FB_OPACITY8 8 bit opacity / alpha buffer }file_header_dtype = numpy.dtype([('magic','int32'),('header_size', 'int32'),('version_major', 'int32'),('version_minor','int32')])frame_length_dtype = numpy.dtype([('length','int32')])frame_header_dtype = numpy.dtype([('version_major','int32'),('version_minor', 'int32'),('lcd_aspect_ratio', 'int32'), ('palette_type','int32'), ('palette_data_start','int32'), ('vp_desc_start','int32'), ('bm_desc_start','int32'), ('bmo_desc_start','int32')])block_description_dtype = numpy.dtype([('fb_type','int32'),('data_start','int32'),('buffer_width','int32'), ('visible_width','int32'),('visible_height','int32'),('margin_left','int32'), ('margin_top','int32'),('margin_right','int32'),('margin_bottom','int32')])myFile = open('test.lvdump','r')file_header=numpy.fromfile(myFile, dtype=file_header_dtype, count=1)frame_length=numpy.fromfile(myFile, dtype=frame_length_dtype, count=1)frame_header=numpy.fromfile(myFile, dtype=frame_header_dtype, count=1)vp_description=numpy.fromfile(myFile, dtype=block_description_dtype, count=1)vp_bpp = fb_type[int(vp_description['fb_type'])]vp_frame_size=vp_description['buffer_width']*vp_description['visible_height']*vp_bpp/8 # in byte !bm_description=numpy.fromfile(myFile, dtype=block_description_dtype, count=1)bm_bpp = fb_type[int(bm_description['fb_type'])]bm_frame_size=bm_description['buffer_width']*bm_description['visible_height']*bm_bpp/8bmo_description=numpy.fromfile(myFile, dtype=block_description_dtype, count=1)bmo_frame_size=bmo_description['buffer_width']*bmo_description['visible_height']*fb_type[int(bmo_description['fb_type'])]/8if vp_description['data_start'] > 0: vp_raw_img=numpy.fromfile(myFile, dtype=numpy.uint8, count=vp_frame_size)### WARNING: the extraction of the YUV format depends on the fb_type. Here I assume the type 2 that is UYVY but this must go in a proper function that takes into account the different cases. y=vp_raw_img[1::2].reshape(int(vp_description['visible_height']),int(vp_description['buffer_width'])) u=numpy.empty(vp_frame_size/2, dtype=numpy.uint8) u[0::2]=vp_raw_img[0::4] u[1::2]=vp_raw_img[0::4] u=u.reshape(int(vp_description['visible_height']),int(vp_description['buffer_width'])) v=numpy.empty(vp_frame_size/2, dtype=numpy.uint8) v[0::2]=vp_raw_img[2::4] v[1::2]=vp_raw_img[2::4] v=v.reshape(int(vp_description['visible_height']),int(vp_description['buffer_width'])) raw_yuv=np.dstack((y,u,v))[:,0:int(vp_description['visible_width']),:] vp_rgb=cv2.cvtColor(raw_yuv, cv2.COLOR_YUV2BGR)if bm_description['data_start'] > 0: bm_raw_img=numpy.fromfile(myFile, dtype=numpy.uint8, count=bm_frame_size) y=bm_raw_img[1::2].reshape(int(bm_description['visible_height']),int(bm_description['buffer_width'])) u=numpy.empty(bm_frame_size/2, dtype=numpy.uint8) u[0::2]=bm_raw_img[0::4] u[1::2]=bm_raw_img[0::4] u=u.reshape(int(bm_description['visible_height']),int(bm_description['buffer_width'])) v=numpy.empty(bm_frame_size/2, dtype=numpy.uint8) v[0::2]=bm_raw_img[2::4] v[1::2]=bm_raw_img[2::4] v=v.reshape(int(bm_description['visible_height']),int(bm_description['buffer_width'])) raw_yuv=np.dstack((y,u,v))[:,0:int(bm_description['visible_width']),:] bm_rgb=cv2.cvtColor(raw_yuv, cv2.COLOR_YUV2BGR)if bmo_description['data_start'] >0: # Not used at the moment bmo_raw_img=numpy.fromfile(myFile, dtype=numpy.int32, count=bmo_frame_size)myFile.close()plt.figure(figsize=(20,10)) plt.imshow(numpy.clip(vp_rgb.astype(numpy.uint16)+bm_rgb.astype(numpy.uint16),0,255).astype(numpy.uint8))
I am using a CANON EOS M10, so the version of CHDK is not the official but a test version.
This problem is generated in the chdkptp.py, but in the installation process it downloads the trunk of chdkptp, so I think it should be the same. The only difference is that chdkptp.py applies some patch to the makefile in order to modify the target from the chdkptp executable to the library chdkptp.so but it should work in the same way.
Because my ultimate goal is not to pass by file but to dump the frame and have it as a numpy array to manipulate. I want to do some image detection to automatically align a telescope (so I will interface it with astrometry).
Started by Stimpy Feature Requests
Started by twomonkeys Hello, I'm a NEWBIE - HELP!! (Newbies assistance, User Guides and thank you notes)
Started by feklee Creative Uses of CHDK
Started by TTRCmedia Hello, I'm a NEWBIE - HELP!! (Newbies assistance, User Guides and thank you notes)
Started by hedwiggggg « 1 2 ... 10 11 » General Discussion and Assistance