edge overlay - page 4 - General Discussion and Assistance - CHDK Forum

edge overlay

  • 41 Replies
  • 27307 Views
Re: edge overlay
« Reply #30 on: 30 / April / 2008, 16:35:39 »
Advertisements
This is useful for panoramas


I just use a Sigma 8mm fisheye.

However, I am not willing to buy a full-frame DSLR so I will use film for my spherical panos yet again this year.


David

Re: edge overlay
« Reply #31 on: 02 / May / 2008, 12:34:21 »
Hi,

Here is a updated (May 8, 2008) version of the edge_overlay code.

During shoot mode half or full press it adds an overlay based on the image edges.
Use the left,right,up,down buttons to shift the overlay.
The edge overlay is frozen when you take a shot and the frozen edges are displayed from then on when you half press.
When you shoot again it goes back to the original behavior:  showing the edges of the current image on half-press.
This behavior is useful when shooting stereo pairs.  For panoramas you would want to freeze the edges after every full press.


This version avoids drawing when menus are displayed
This version adds a grid that matches the Canon grid.
This version corrects flaky behavior caused by multiple calls during one full-press.


Code: (cpp) [Select]

// Code to test the idea of an edge overlay
// Put  edge_overlay(); after the line histogram_process();


// Put the following after  the line #include "motion_detector.h" in main.c
#include "gui_draw.h"
 
// until the edge thresh is put into conf structure I have hardcoded the threshold  see "thresh" below
static char * imgbuf = 0;

#define MARGIN 30
#define CALCYMARGIN 3
#define EDGECOLOR 0x66
#define NSTAGES 4
#define XINC 6
#define YINC 2
#define XGRID1 120
#define XGRID2 240
#define YGRID1 80
#define YGRID2 160

void edge_overlay(){
static int inmem=0;
static int viewport_height;
static int viewport_width;// screenwidth * 3
static int viewport_size;
static int shotTaken = 0;
static int imgmem = 0;
static int ymin = 0;
static  int thresh = 40;
static int xoffset = 0;
static int yoffset = 0;
static int full_press = 0;//cure for flaky behavior. due to multiple  returns to the scrip during one full press
static char strbuf[7] = "Frozen";
  static unsigned char *img;
int i, hi, c;
int x, y, h, v, ymax, y1, x1, y2;
char * ptrh1;
char * ptrh2;
char * ptrv1;
char * ptrv2;
char * optr;

// if(!conf.edge_thresh) return;

img = vid_get_viewport_fb();
    viewport_height = vid_get_viewport_height();
viewport_width = screen_width * 3;
    viewport_size = viewport_height * screen_width;
if(imgbuf == 0) imgbuf = malloc(viewport_size * 3);

if((mode_get()&MODE_MASK) != MODE_PLAY) {
if (kbd_is_key_pressed(KEY_RIGHT)) {
xoffset -=XINC;
}
if (kbd_is_key_pressed(KEY_LEFT)) {
xoffset +=XINC;
}
if (kbd_is_key_pressed(KEY_DOWN)) {
yoffset -=YINC;
}
if (kbd_is_key_pressed(KEY_UP)) {
yoffset +=YINC;
}

if (kbd_is_key_pressed(KEY_SHOOT_HALF)||kbd_is_key_pressed(KEY_SHOOT_FULL)) {
if (kbd_is_key_pressed(KEY_SHOOT_FULL) && !full_press) {
shotTaken = 1 - shotTaken;
memcpy(imgbuf,img,viewport_size * 3);
ymin = CALCYMARGIN;
inmem = 1;
full_press = 1;
xoffset = 0;
yoffset = 0;
return;
}
if(shotTaken) {
return;
}
memcpy(imgbuf,img,viewport_size * 3);
ymin = CALCYMARGIN;
inmem = 1;
xoffset = 0;
yoffset = 0;
return;
}
else full_press = 0;
if (inmem && (ymin < screen_height-CALCYMARGIN)) {
ymax = ymin + (screen_height - 2 * CALCYMARGIN) / NSTAGES;
if(ymax > screen_height - CALCYMARGIN) ymax = screen_height - CALCYMARGIN;
for (y=ymin; y<ymax; y++) {
ptrh1 = imgbuf + y * viewport_width + 7;
ptrh2 = imgbuf + y * viewport_width - 5;
ptrv1 = imgbuf + (y + 1) * viewport_width + 1;
ptrv2 = imgbuf + (y - 1) * viewport_width + 1;
optr = imgbuf + y * viewport_width + 3;
for (x=12; x<(screen_width- 4) * 3; x+=6) {
h = ptrh1[x] - ptrh2[x];
if(h  < 0) h = -h;
v = ptrv1[x] - ptrv2[x];
if(v  < 0) v = -v;
optr[x] = h + v;
h = ptrh1[x + 3] - ptrh2[x + 3];
if(h  < 0) h = -h;
v = ptrv1[x + 3] - ptrv2[x + 3];
if(v  < 0) v = -v;
optr[x + 2] = h + v;
}
}
ymin += (screen_height - 2 * CALCYMARGIN) / NSTAGES;
return;
}
if(inmem &&(ymin >= screen_height-CALCYMARGIN) &&
((gui_get_mode() == GUI_MODE_NONE) || (gui_get_mode() == GUI_MODE_ALT))){
// thresh = (conf.edge_thresh - 1) * 12;
for (y=MARGIN; y<screen_height-MARGIN; y++) {
y1 = y + yoffset;
if((y1 < CALCYMARGIN) || (y1 >= screen_height - CALCYMARGIN)) {
for (x=MARGIN; x < screen_width - MARGIN; x+=2) {
draw_pixel(x, y, 0);
draw_pixel(x+1, y, 0);
}
}
else {
for (x=MARGIN; x < screen_width - MARGIN; x+=2) {
x1 = x + xoffset;
if((x1 < 12) || (x1 >= screen_width-13)) {
draw_pixel(x, y, 0);
draw_pixel(x+1, y, 0);
}
else {
c = 0;
if(imgbuf[y1 * viewport_width + x1 * 3 + 3]  > thresh)
c = EDGECOLOR;
draw_pixel(x, y, c);
c = 0;
if(imgbuf[y1 * viewport_width + x1 * 3 + 5]  > thresh)
c = EDGECOLOR;
draw_pixel(x+1, y, c);
}
}
}
for (y2=MARGIN; y2<screen_height-MARGIN; y2++) {
draw_pixel(XGRID1,y2,0xff);
draw_pixel(XGRID2,y2,0xff);
if(y2 == YGRID1) for (x=MARGIN; x < screen_width - MARGIN; x++) draw_pixel(x,y2,0xff);
if(y2 == YGRID2) for (x=MARGIN; x < screen_width - MARGIN; x++) draw_pixel(x,y2,0xff);
}
if(shotTaken) draw_string(30, 10, strbuf, conf.osd_color);
}
return;
}
}
else {
full_press = 0;
inmem = 0;
shotTaken = 0;
ymin = 0;
xoffset = 0;
yoffset = 0;
}
return;
}
 
//End of edge detector code.  next put  edge_overlay(); after the line histogram_process();

« Last Edit: 08 / May / 2008, 12:47:22 by hiker_jon »

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: edge overlay
« Reply #32 on: 02 / May / 2008, 12:50:58 »
Code: [Select]
(canon_menu_active==(int)&canon_menu_active-4) && (canon_shoot_menu_active==0)if this statement is true, neither canon menu nor the function menu are popped up.
dont ask me about the -4 thing, i copied it from the source, used it in my own function - it works. these get defined in stubs_min.s by the way

Re: edge overlay
« Reply #33 on: 02 / May / 2008, 13:58:00 »
Thanks,
That works.  I have modified the code I posted.

The previous behavior was:
When you press menu (ie Canon menu, not in alt mode) you see a live image plus my edge overlay in a different color frozen at the time you pressed menu.   I write to the screen using draw_pixel using 0 (for transparent) and a color 0x26.  So the 0 was overwriting the canon menu and causing the display to show the last image.  But why was my color changed?  Why does 0x26 have different meanings at different times?  I guess I have a lot to learn about how the screen works.

Jon
« Last Edit: 02 / May / 2008, 14:00:44 by hiker_jon »

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: edge overlay
« Reply #34 on: 02 / May / 2008, 14:09:26 »
canon keeps 4 different color palettes, one for record mode, one for playback and i think 1 each for menu and func menu.

Re: edge overlay
« Reply #35 on: 08 / May / 2008, 12:50:13 »
I have updated the code to fix some flakiness and changed the overlay color.  The code now displays the word "Frozen" when the edge overlay is frozen.

Jon

*

Offline vine

  • ***
  • 124
  • A560
    • my chdk page
Re: edge overlay
« Reply #36 on: 22 / May / 2008, 08:31:23 »
I just tried it on my A560 and it works very well. Great addition to CHDK!

*EDIT
Surely it is supposed to work for the whole display? If I use your code without change It only acts on a smaller are in the center of the display (hope you know what I mean, here is an image of it: http://worldswithinworlds.de/misc_image_dump/PICT0079.JPG)
I guess I'll have to take a closer look at the code behind it after all ;)
« Last Edit: 22 / May / 2008, 08:49:42 by vine »
my photo map

my chdk page with tutorials, scripts and more

>> finally back from vacation (was a bit longer than intended) <<

Re: edge overlay
« Reply #37 on: 23 / May / 2008, 16:11:12 »
Surely it is supposed to work for the whole display?


If it overlaps any on-screen display elements that are situated around the edges of the screen, you get annoying flickering.

*

Offline vine

  • ***
  • 124
  • A560
    • my chdk page
Re: edge overlay
« Reply #38 on: 24 / May / 2008, 12:21:43 »
Thanks for clearing that up for me Microfunguy
Any suggestion on how to implement a quick and simple on/off option?
my photo map

my chdk page with tutorials, scripts and more

>> finally back from vacation (was a bit longer than intended) <<

Re: edge overlay
« Reply #39 on: 24 / May / 2008, 13:21:15 »
Any suggestion on how to implement a quick and simple on/off option?

Well, i am using it with my own SDM build so I turn-off any OSD's when outline mode is enabled and I turn-off Canon displays with the DISPLAY button.

I have not studied the trunk CHDK build recently  ;)

David

 

Related Topics


SimplePortal © 2008-2014, SimplePortal