Note that there are some explanatory texts on larger screens.

plurals
  1. POSegmentation Fault (core dumped) in pixel manipulation
    primarykey
    data
    text
    <p>I am trying to get the bird's eye view of an image. I am altering the pixel intensity in two <em>for-loops</em> going over row and column respectively. </p> <pre><code>birdeyeview_img.at&lt;uchar&gt;(p,q)=(int)undistor_img.at&lt;uchar&gt;(round(corr_x),round(corr_y); </code></pre> <p>I am getting: <code>Segmentation Fault (Core Dumped)</code>. How do I alter the pixel intensity, without getting nay such error? My undistorted image is a grayscale image. Now I made few changes, it runs but doesn't give proper result, only a part of the code shows pixel manipulations : // </p> <pre><code>This code will take undistorted images as input and give the bird's eye view using them // First we need to calculate the homography matrix #include "opencv2/highgui/highgui.hpp" #include "opencv2/core/core.hpp" #include "opencv2/imgproc/imgproc_c.h" #include &lt;iostream&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;math.h&gt; using namespace cv; using namespace std; int main() { //loading the undistorted image Mat undistor_img=imread("undistorted images/img_u1.jpg", CV_WINDOW_AUTOSIZE); namedWindow("undistorted image"); imshow("undistorted image",undistor_img); // storing the resolution values float resolution_x=50, resolution_y=50; // height and width for bird's eye view float heightBirdEyeView=500; float widthBirdEyeView=700; //camera height and tilt float height_camera = 125; float tilt_camera=12; float halfAngle=180; float pi=3.14159; float alpha = tilt_camera/halfAngle*pi; //focal length in x and y float focal_length_x = 354.05700; float focal_length_y = 353.65297; //generate transformation matrix float H1[3][3]={resolution_x,0,widthBirdEyeView/2+1, 0,-1*resolution_y,heightBirdEyeView, 0,0,1}; Mat transformation_matrix(3,3,CV_32FC1,H1); cout&lt;&lt;"transformation matrix="&lt;&lt;endl&lt;&lt;transformation_matrix&lt;&lt;endl&lt;&lt;endl; //generate top view matrix float H2[3][3]={height_camera/focal_length_x,0,0, 0,0,height_camera, 0,cos(alpha)/focal_length_y,sin(alpha)}; Mat topview_matrix(3,3,CV_32FC1,H2); cout&lt;&lt;"topview matrix="&lt;&lt;endl&lt;&lt;topview_matrix&lt;&lt;endl&lt;&lt;endl; //generate scale matrix float H3[3][3]={1,0,undistor_img.rows, 0,1,undistor_img.rows, 0,0,1}; Mat scale_matrix(3,3,CV_32FC1,H3); cout&lt;&lt;"scale matrix="&lt;&lt;endl&lt;&lt;scale_matrix&lt;&lt;endl&lt;&lt;endl; //generate the homography matrix from these matrices Mat homography_matrix=transformation_matrix*topview_matrix/scale_matrix; cout&lt;&lt;"homography matrix"&lt;&lt;endl&lt;&lt;homography_matrix&lt;&lt;endl&lt;&lt;endl; cout&lt;&lt;homography_matrix.at&lt;float&gt;(0,0)&lt;&lt;endl; //now we need transpose of homography matrix Mat transpose_homography_matrix(3,3,CV_32FC1); for(int i=0;i&lt;3;i++) { for(int j=0;j&lt;3;j++) transpose_homography_matrix.at&lt;float&gt;(i,j)=homography_matrix.at&lt;float&gt;(j,i); } cout&lt;&lt;"transpose of homography matrix"&lt;&lt;endl&lt;&lt;transpose_homography_matrix&lt;&lt;endl&lt;&lt;endl; Mat birdeyeview_img(heightBirdEyeView, widthBirdEyeView,CV_32FC3); namedWindow("bird's eye view image"); Mat p_new(3,1,CV_32FC1); // this will give the coordinates in the bird's eye view float corrected_x,corrected_y; int a=0,b=0; // counters for if and else blocks //now we need matrix with coordinates of the image plane, to be projected for(int p=0; p&lt;heightBirdEyeView;p++) { uchar* data= undistor_img.ptr&lt;uchar&gt;(p); uchar* hdata= birdeyeview_img.ptr&lt;uchar&gt;(p); for(int q=0;q&lt;widthBirdEyeView;q++) { int M[]={q,p,1}; Mat p_old(3,1,CV_32FC1,M); //holding the positions in undistorted image //cout&lt;&lt;transpose_homography_matrix*p_old&lt;&lt;endl; p_new=transpose_homography_matrix*p_old; corrected_x=p_new.at&lt;float&gt;(0,0)/p_new.at&lt;float&gt;(2,0); corrected_y=p_new.at&lt;float&gt;(1,0)/p_new.at&lt;float&gt;(2,0); if (((abs(corrected_y)&gt;=1)&amp;&amp;(corrected_y&lt;=undistor_img.rows))&amp;&amp;((abs(corrected_x)&gt;=1)&amp;&amp;(corrected_x&lt;=undistor_img.cols))) { /*hdata[q]=(1- (corrected_y-floor(corrected_y)))*(1-(corrected_x-floor(corrected_x)))*data[q] +(1-( corrected_y-floor(corrected_y)))*(corrected_x-floor(corrected_x))*data[q] +( corrected_y-floor(corrected_y))*(1-(corrected_x-floor(corrected_x)))*data[q] +( corrected_y-floor(corrected_y))*(corrected_x-floor(corrected_x))*data[q];*/ hdata[q]=(1- (corrected_y-floor(corrected_y)))*(1-(corrected_x-floor(corrected_x)))*(undistor_img.at&lt;uchar&gt;(floor(corrected_y),floor(corrected_x)))+(1-( corrected_y-floor(corrected_y)))*(corrected_x-floor(corrected_x))*(undistor_img.at&lt;uchar&gt;(floor(corrected_y), ceil(corrected_x)))+(corrected_y-floor(corrected_y))*(1-(corrected_x-floor(corrected_x)))*(undistor_img.at&lt;uchar&gt;(ceil(corrected_y),floor(corrected_x)))+(corrected_y-floor(corrected_y))*(corrected_x-floor(corrected_x))*(undistor_img.at&lt;uchar&gt;(ceil(corrected_y), ceil(corrected_x))); a++;} else{ b++; hdata[q]= undistor_img.at&lt;uchar&gt;(p,q); } } } //cout&lt;&lt;"if was read"&lt;&lt;a &lt;&lt;"times"&lt;&lt;endl; //cout&lt;&lt;"else was read"&lt;&lt;b &lt;&lt;"times"&lt;&lt;endl; imshow("bird's eye view image",birdeyeview_img); //cout&lt;&lt;"input size="&lt;&lt;undistor_img.rows&lt;&lt;"X"&lt;&lt;undistor_img.cols&lt;&lt;endl; //cout&lt;&lt;"result size="&lt;&lt;birdeyeview_img.rows&lt;&lt;"X"&lt;&lt;birdeyeview_img.cols&lt;&lt;endl; cvWaitKey(); } </code></pre> <p>In what other ways can I change pixel values(in birdeyeview_img) , using the pixel values from another image (undistor_img) ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload