Ask Your Question

Ayesha Siddique's profile - activity

2020-11-15 00:55:18 -0600 received badge  Popular Question (source)
2020-06-24 14:38:00 -0600 received badge  Popular Question (source)
2017-06-06 07:08:00 -0600 commented question Error reading text file into Mat in OpenCV

Thank-you.

2017-06-05 07:22:00 -0600 commented question Error reading text file into Mat in OpenCV

I've debugged this code around while loop. It doesn't go inside this while loop

2017-06-05 04:53:48 -0600 asked a question Error reading text file into Mat in OpenCV

Hi!

Using OpenCV 3.0 and Visual Studio Professional 2013

I'm facing difficulty in reading a readable text file, generated by MATLAB, in OpenCV. The text file contains signed floating point numbers. One number on each line and total number of lines are 2241 but there is just single column. I want to read this data in to a matrix with just one column and 2241 rows.

But..

The debugger says this next to fstream in watch window: "Error reading characters of string"

*#include <iostream>
*#include <fstream>
*#include "opencv2/imgcodecs.hpp"

*#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;

void printUsage();
int parseCmdArgs(int argc, char** argv);


Mat ReadMatFromTxt(string filename);

int main(int argc, char* argv[])
{
    string filename = "P:\\svd\\main_CC++\\build\\training_filter.txt";
Mat out = ReadMatFromTxt(filename);

waitKey();
return 0;
}


Mat ReadMatFromTxt(string filename)
{
double m;
ifstream fileStream(filename.c_str(), ifstream::in);
if (!fileStream) {
    string error_message = "No valid input file was given, please check the given filename.";
    CV_Error(Error::StsBadArg, error_message);
}
int rows = 1;

char enterChar;
int numOfLines_InTextFile = 0;
while (fileStream.get(enterChar)) {
    if (enterChar == '\n') {
        ++numOfLines_InTextFile;
    }
}

int cols = numOfLines_InTextFile;

Mat out = Mat::zeros(rows, cols, CV_64FC1);//Matrix to store values

    int cnt = 0;//index starts from 0
while (fileStream >> m)
{
    int temprow = cnt / cols;
    int tempcol = cnt % cols;
    out.at<double>(temprow, tempcol) = m;
    cnt++;
}

fileStream.close();
return out;
}
2017-05-31 06:06:50 -0600 commented answer Error in making graphs in OpenCV

Thank-you @berak

2017-05-30 01:06:23 -0600 asked a question Error in making graphs in OpenCV

Hi!

I want to generate plots in OpenCV, using the following link:

http://answers.opencv.org/question/73233/how-do-you-plot-graphs-in-opencv-projects/

For this purpose, I added the following files (from https://github.com/opencv/opencv_contrib/tree/master/modules/plot in OpenCV folder as mentioned below.

plot.hpp >> opencv\build\include\opencv2

precomp.hpp >> opencv\build\include\opencv2

plot.cpp >> opencv\sources\modules\plot\src

but after building the code, I receive the following error

Error 2 error LNK1120: 1 unresolved externals

Error 1 error LNK2019: unresolved external symbol "struct cv::Ptr<class cv::plot::plot2d=""> __cdecl cv::plot::createPlot2d(class cv::_InputArray const &)" (?createPlot2d@plot@cv@@YA?AU?$Ptr@VPlot2d@plot@cv@@@2@ABV_InputArray@2@@Z) referenced in function _main

Please help me in resolving this issue.

2016-08-23 05:51:45 -0600 commented question matrices as function arguments

?????????????

2016-08-22 14:30:03 -0600 commented question matrices as function arguments

non-continuous mats meaning?

2016-08-20 08:28:58 -0600 commented question matrices as function arguments

please check the edited question now.

2016-08-20 07:53:40 -0600 asked a question matrices as function arguments

I'm dealing with c and cpp files in my project. I've some data in matrix form in .cpp file now and I want to use this matrix data in .c file. As .c files don't use matrices but only .cpp files use... so, matrices can't be passed accross functions in this case.

How should I deal with such situation in openCV?

Example:

I've the following function in .cpp file.

extern "C"
{
    unsigned char *img_four_regions(unsigned char *img1);
}


unsigned char *img_four_regions(unsigned char *img1)
{
    unsigned char *top_left;
top_left = img1;

cv::Mat TempMat = cv::Mat(138, 640, CV_8UC1, top_left);

Mat temp_top_right;
Mat temp_top_left;
Mat temp_bottom_right;
Mat temp_bottom_left;

TempMat(Range(0, 69), Range(0, 320)).copyTo(temp_top_right);
imshow("top right", temp_top_right);
waitKey(0);

TempMat(Range(0, 69), Range(321, 640)).copyTo(temp_top_left);
imshow("top right", temp_top_left);
waitKey(0);

TempMat(Range(70, 138), Range(0, 320)).copyTo(temp_bottom_right);
imshow("top right", temp_bottom_right);
waitKey(0);

TempMat(Range(70, 138), Range(321, 640)).copyTo(temp_bottom_left);
imshow("top right", temp_bottom_left);
waitKey(0);

Now I want to use the matrices named "temp_bottom_right, temp_bottom_left, temp_top_right, temp_top_left" in .c file by calling this function.

2016-08-04 04:41:58 -0600 received badge  Autobiographer
2016-08-04 03:40:52 -0600 commented answer copy even and columns columns from a matrix

thankyou! I was also residing near this approach

2016-08-03 06:05:48 -0600 asked a question copy even and columns columns from a matrix

How to copy even columns (column numbers: 0, 2, 4) from a matrix to another matrix (column numbers: 1, 2, 3)? and how to copy odd columns (column numbers: 1, 3, 5) from a matrix to another matrix (column numbers: 1, 2, 3)?

2016-07-29 05:44:45 -0600 commented answer How to store the output "point2f point[0]" for future use in lkdemo file of opencv?

@berak...????????

2016-07-28 02:58:43 -0600 marked best answer How to store the output "point2f point[0]" for future use in lkdemo file of opencv?

In lkdemo file of opencv, the points with x,y co-ordinates) were saved in "Point2f point" and on each iteration or in every part of the loop, points[0] is updated with x and y coordinates. I want to store points of each iteration in a memory block or at one place so that I can use these points later. How can I do that? I tried it by coping the points to a float 2D array in this way:

in every part of loop, copy all points to the first column of a 2D array then, in next part of loop, copy all points to the second column of a 2D array then, . . . . go up to last frame in this way.

but the problem is that point2f point can't be copied to a float 2D array or in other words, its not allowed in opencv.

Any ideas?

2016-07-28 02:58:24 -0600 commented answer How to store the output "point2f point[0]" for future use in lkdemo file of opencv?

@LBerger and @berak How can I copy the values in points[1] to the columns of a new matrix?

2016-06-16 11:26:09 -0600 commented question Homography transformation

H matrix is not empty and I've verified it.

Actually, I've stored X and Y component of every feature in one frame in smooth (fltrd) and original (orgnl) matrices and then calculated transformation matrix because I thought that the findhomography transformation needs both X and Y components. I might be wrong so, please clear my concept, if it should be out of the loop. If it should be out of the loop then I should two homography matrices seperately using first the whole smooth and original X components and then secondly, the whole smooth and original Y components. Isn't it?

2016-06-16 02:17:59 -0600 commented question cos function calculation in Opencv

@LBerger please help me here link text

2016-06-16 02:16:43 -0600 commented answer load matrix from values in text file

@berak please help me here link text

2016-06-16 02:12:09 -0600 asked a question Homography transformation

I've X and Y components of original and smooth trajectories saved in following matrices, whose rows corresponds to frame number and columns corresponds to features.

Mr -> X components of original trajectories (225 rows and 51 columns) Mc -> Y components of original trajectories (225 rows and 51 columns) Mrf -> X components of smooth trajectories (225 rows and 26 columns) Mcf -> Y components of smooth trajectories (225 rows and 26 columns)

Now, For each frame, I did this...For computing the homography matrix between original and smooth trajectories. I stored the X and Y component of every feature (original features' locations) in matrix's (orgnl) first and second column respectively. This matrix ognl has 225 rows as there were 225 features. Similarly, I stored the X and Y component of every feature (smooth features' locations) in matrix's (fltrd) first and second column respectively. This matrix ognl has 225 rows as there were 225 features. No, I computed homography matrix "H" that has 3 rows and 3 columns.

Now, I want to apply the transformation on original feature trajectories so that I can check that either they are getting transformed or not. For this, I used OpenCV's function "transform" whose input is matrix "orgnl" and hompgraphy matrix "H"and output is the matrix "output" having two columns and 225 rows.

The problem is that when I run the following code, it throws an exception at some memory location corresponding to homography matrix and this exception appears on executing the function "transform". Before, this function the code runs smoothly.

Please help me out of this issue. If I'm doing something wrong then please notify me as soon as possible.

cv::Mat orgnl(225, 2, DataType<float>::type);
cv::Mat fltrd(225, 2, DataType<float>::type);
cv::Mat output(225, 2, DataType<float>::type);
cv::Mat H(3, 3, DataType<float>::type);

for (int i = 0; i < Mrf.cols; i++)
{
    for (int j = 0; j < Mrf.rows; j++)
    {   
        Mr.col(i).row(j).copyTo(orgnl.col(0).row(j));
        Mc.col(i).row(j).copyTo(orgnl.col(1).row(j));
        Mrf.col(i).row(j).copyTo(fltrd.col(0).row(j));
        Mcf.col(i).row(j).copyTo(fltrd.col(1).row(j));
    }
        H = findHomography(orgnl, fltrd, CV_RANSAC);

        transform(orgnl, output, H);

}
2016-06-10 02:58:07 -0600 commented question bmp to pgm conversion

@LBerger Can you please help me here link text

2016-06-10 02:54:55 -0600 marked best answer how to remove specific rows from a matrix

I want to delete the rows containing all zeros from a matrix... I can do so in MATLAB but how can I do it in OpenCV? I've searched over the internet but could not understand....

2016-06-10 02:52:24 -0600 edited answer How to copy specific number of columns from a matrix to another matrix?

This can be done by defining first the size of matrix B as the number of columns that you want after deletion and same number of rows as in matrix A.

The command is A.col(a).copyTo(B.col(b)) and you must run a loop over command according to your copying pattern between two matrices.

2016-06-10 02:51:02 -0600 asked a question load matrix from values in text file

I've written a matrix (rows: 238 and columns 51) in a text file using MATLAB. In text file, the columns are separated by tab and each line in the text fie corresponds to a row of that matrix. Now, I want to read that file into a matrix in OpenCV. How can I do it?

I've read a number of posts where they were using "stdafx.h" header file in their code but I can't add it to my code because I think that I don't have this header file. I can't understand also. So please help me out here.

2016-04-29 06:36:26 -0600 marked best answer How to copy specific number of columns from a matrix to another matrix?

I know the way to copy specific rows from one matrix to another but how can I copy only a specific number of columns from one matrix to another? For example, if we have 10x10 matrix A (10 rows and 10 columns)and I want to copy only the columns ranging from 1 to 5 to another matrix B. Is it possible?

Note: I can't delete the columns from matrix A first.