Ask Your Question

Niessoh's profile - activity

2020-10-27 02:50:17 -0600 received badge  Famous Question (source)
2020-07-20 04:02:30 -0600 received badge  Enthusiast
2020-07-19 06:42:08 -0600 commented question Why is setting frame height and width prevents saving the webcam stream to disk?

I also need to add that If I use larger numbers such as 640, 480, the recordings are saved, its as if opencv has issues

2020-07-19 06:40:59 -0600 asked a question Why is setting frame height and width prevents saving the webcam stream to disk?

Why is setting frame height and width prevents saving the webcam stream to disk? Hello everyone. Excuse me for the vagu

2019-03-14 10:45:49 -0600 received badge  Notable Question (source)
2018-01-27 14:40:45 -0600 received badge  Popular Question (source)
2018-01-12 07:43:56 -0600 received badge  Notable Question (source)
2017-08-18 13:57:08 -0600 received badge  Student (source)
2017-08-18 13:56:53 -0600 received badge  Popular Question (source)
2017-08-17 20:05:39 -0600 commented question Why am I Getting distorted images after sending them from C# to OpenCV in C++?

Thank you @Tetragramm. yes part of the issue was the step size. there are still other issues for example, when I resize the image in C# and pass it to the dll, although the full image works, the resized one has scan lines in it! like an old black and white TV with vertical scan lines! (here is screeshot : http://imgur.com/a/UvkhH) if I use opencv interal resize, its fine, if I send in the full size image it works, but when I use a resized one this is what I get ) I'll dig further and if I come up with an answer i update this post. Thank you for the heads-up

2017-08-17 07:35:20 -0600 asked a question Why am I Getting distorted images after sending them from C# to OpenCV in C++?

I created a C DLL out of my C++ class which uses OpenCV for image manipulations and want to use this dll in my C# application. Currently, this is how I have implemented it :

#ifdef CDLL2_EXPORTS
#define CDLL2_API __declspec(dllexport)
#else
#define CDLL2_API __declspec(dllimport)
#endif

#include "../classification.h" 
extern "C"
{
    CDLL2_API void Classify_image(unsigned char* img_pointer, unsigned int height, unsigned int width, char* out_result, int* length_of_out_result, int top_n_results = 2);
    //...
}

C# related code :DLL Import section:

//Dll import 
[DllImport(@"CDll2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
static extern void Classify_Image(IntPtr img, uint height, uint width, byte[] out_result, out int out_result_length, int top_n_results = 2);

The actual function sending the image to the DLL:

//...
//main code 
private string Classify(int top_n)
{
    byte[] res = new byte[200];
    int len;
    Bitmap img = new Bitmap(txtImagePath.Text);
    BitmapData bmpData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), 
                                      ImageLockMode.ReadWrite,  
                                      PixelFormat.Format24bppRgb);
    Classify_Image(bmpData.Scan0, (uint)bmpData.Height, (uint)bmpData.Width, res, out len, top_n);
    img.UnlockBits(bmpData); //Remember to unlock!!!
    //...
}

and the C++ code in the DLL :

CDLL2_API void Classify_Image(unsigned char* img_pointer, unsigned int height, unsigned int width,
                              char* out_result, int* length_of_out_result, int top_n_results)
    {
        auto classifier = reinterpret_cast<Classifier*>(GetHandle());

        cv::Mat img = cv::Mat(height, width, CV_8UC3, (void*)img_pointer, Mat::AUTO_STEP);

        std::vector<Prediction> result = classifier->Classify(img, top_n_results);

        //...
        *length_of_out_result = ss.str().length();
    }

This works prefectly with some images but it doesnt work with others, for example when I try to imshow the image in the Classify_Image, right after being created form the data sent by C# application, I am faced with images like this : problematic example:
image description

fine example :
image description

Here are the original images for further investigations(may be nsfw for some people so I place the link) :
http://answers.opencv.org/upfiles/150...
http://answers.opencv.org/upfiles/150...

My own thought about the cause of the issue, is I am creating the image regardless of its true type, (setting all images to CV_8UC3 and Mat::AUTO_STEP. thats why some images are fine and some others are not. The problem is, I dont know how I'm supposed to assign the correct type to each image at creation time back in C++. (if thats the cause for such issue, if it is not then I have no idea what else could be doing this) Any help is greatly appreciated .

2017-08-17 07:07:28 -0600 commented question cv::resize() fails with access violation error (caused by <struct at NULL>)

@berak: you are right, I'm sorry for the trouble. I ask a new question and explain everything there

2017-08-17 07:00:00 -0600 commented question cv::resize() fails with access violation error (caused by <struct at NULL>)

@berak: you are right, I'm sorry for the trouble. I ask a new question and explain everything there

2017-08-16 04:16:35 -0600 commented question cv::resize() fails with access violation error (caused by <struct at NULL>)

I notriced this is caused by the sample. and if I create a black image for example and try to resize it, there would be no problem at all. though, I have no idea what specifically is wrong with sample image!

2017-08-16 04:15:39 -0600 commented question cv::resize() fails with access violation error (caused by <struct at NULL>)

this is a follow up question from here : https://stackoverflow.com/questions/4...

2017-08-16 02:12:38 -0600 asked a question cv::resize() fails with access violation error (caused by <struct at NULL>)

I'm trying to do a simple resize using opencv which ends up crashing!
This is the example code which the access violation occurs:

void Classifier::Preprocess(const cv::Mat& img, std::vector<cv::Mat>* input_channels)
{
    /* Convert the input image to the input image format of the network. */
    cv::Mat sample;
    if (img.channels() == 3 && num_channels_ == 1)
        cv::cvtColor(img, sample, cv::COLOR_BGR2GRAY);
    else if (img.channels() == 4 && num_channels_ == 1)
        cv::cvtColor(img, sample, cv::COLOR_BGRA2GRAY);
    else if (img.channels() == 4 && num_channels_ == 3)
        cv::cvtColor(img, sample, cv::COLOR_BGRA2BGR);
    else if (img.channels() == 1 && num_channels_ == 3)
        cv::cvtColor(img, sample, cv::COLOR_GRAY2BGR);
    else
        sample = img;

    //resize image according to the input
    cv::Mat sample_resized;
    Size size(input_geometry_.width,input_geometry_.height );

    if (sample.size() != input_geometry_)
        cv::resize(sample, sample_resized, size);
    else
        sample_resized = sample;

    //...
}

This is what I get in my C# solution when debugging :

Exception thrown at 0x00007FF8C8D9AA90 (opencv_imgproc310d.dll) in Classification Using dotNet.exe: 0xC0000005: Access violation reading location 0x0000018B000F2000.

If there is a handler for this exception, the program may be safely continued.

When I debug into the opencv code, I can see that sz is a null struct(<struct at NULL>) :

template<typename _Tp> inline
Size_<_Tp>::Size_(const Size_& sz)
    : width(sz.width), height(sz.height) {}

and this clearly causes the access violation!.

What is wrong here and what should I do ?

2016-02-12 03:16:55 -0600 asked a question Is this the correct way of porting HTML5 drawing to OpenCV?

Hello All, Im trying to port a java script application into c++. this javascript app has a graphing and plotting section which is coded like this :

// can be used to graph loss, or accuract over time
var Graph = function(options) {
var options = options || {};
this.step_horizon = options.step_horizon || 1000;

this.pts = [];

this.maxy = -9999;
this.miny = 9999;
}

Graph.prototype = {
// canv is the canvas we wish to update with this new datapoint
add: function(step, y) {
  var time = new Date().getTime(); // in ms
  if(y>this.maxy*0.99) this.maxy = y*1.05;
  if(y<this.miny*1.01) this.miny = y*0.95;

  this.pts.push({step: step, time: time, y: y});
  if(step > this.step_horizon) this.step_horizon *= 2;
},
// elt is a canvas we wish to draw into
drawSelf: function(canv) {

  var pad = 25;
  var H = canv.height;
  var W = canv.width;
  var ctx = canv.getContext('2d');

  ctx.clearRect(0, 0, W, H);
  ctx.font="10px Georgia";

  var f2t = function(x) {
    var dd = 1.0 * Math.pow(10, 2);
    return '' + Math.floor(x*dd)/dd;
  }

  // draw guidelines and values
  ctx.strokeStyle = "red";//color of the line
  ctx.beginPath();//makes ready for drawing a new line!
  var ng = 10;
  for(var i=0;i<=ng;i++) {
    var xpos = i/ng*(W-2*pad)+pad;
    ctx.moveTo(xpos, pad);//draws aline from this point
    ctx.lineTo(xpos, H-pad);//to this point
    ctx.fillText(f2t(i/ng*this.step_horizon/1000)+'k',xpos,H-pad+14);
  }
  for(var i=0;i<=ng;i++) {
    var ypos = i/ng*(H-2*pad)+pad;
    ctx.moveTo(pad, ypos);
    ctx.lineTo(W-pad, ypos);
    ctx.fillText(f2t((ng-i)/ng*(this.maxy-this.miny) + this.miny), 0, ypos);
  }
  ctx.stroke();//saves the drawing on the canvas

  var N = this.pts.length;
  if(N<2) return;

  // draw the actual curve
  var t = function(x, y, s) {
    var tx = x / s.step_horizon * (W-pad*2) + pad;
    var ty = H - ((y-s.miny) / (s.maxy-s.miny) * (H-pad*2) + pad);
    return {tx:tx, ty:ty}
  }

  ctx.strokeStyle = "red";
  ctx.beginPath()
  for(var i=0;i<N;i++) {
    // draw line from i-1 to i
    var p = this.pts[i];
    var pt = t(p.step, p.y, this);
    if(i===0) ctx.moveTo(pt.tx, pt.ty);
    else ctx.lineTo(pt.tx, pt.ty);
  }
  ctx.stroke();
}
}

I tried to convert this to C++ using OpenCV, but since OpenCV doesnt have a concept like Canvas, I'm stuck how to get around this limitation. this is the class counter part so far.

class Graph
{

    // can be used to graph loss, or accuract over time
    //  auto Graph = function(options) {
public:

    struct Options
    {
        int step_horizon;
        int maxy;
        int miny;

    };
    int step_horizon;
    int maxy;
    int miny;

    struct ptsInfo
    {
        int step;
        long long time;
        int y;
    };

    struct txty
    {
        int tx;
        int ty;
    };

    std::vector< ptsInfo> pts;



    Graph(Options options)
    {
        auto options = options || {};
        this->step_horizon = options.step_horizon || 1000;
        //this->pts = [];
        this->maxy = -9999;
        this->miny = 9999;
    }

    // canv is the canvas we wish to update with this new datapoint
    void add(int step, int y)
    {
        auto time = Global::GetSystemDate ...
(more)
2015-10-08 02:58:41 -0600 commented answer How can I convert an image into a 1d vector in c++?

Thanks but the standard constructor fails with error message: cant convert argument 1 uchar* to const std::allocator<_Ty>& before that I tried to convert the image to grayslcale using cv::imread(fileName, cv::IMREAD_GRAYSCALE) So it doesnt compile now

2015-10-08 02:56:53 -0600 commented question How can I convert an image into a 1d vector in c++?

@berak: I created the whole neural networks library, its not vectorized yet and I am experimenting the differences, thats why I am not allowed to use opencvs ml algorithms at the moment. By the way doing : cv::Mat mat = cv::imread(fileName, cv::IMREAD_GRAYSCALE);

mat.convertTo(mat,CV_32F);

std::vector<float> array(mat.data);

fails as well, complains about the conversion from uchar* to const std::allocator<_Ty>&.

2015-10-08 02:53:14 -0600 received badge  Supporter (source)
2015-10-08 02:00:28 -0600 asked a question How can I convert an image into a 1d vector in c++?

Hello everyone, I'm new to OpenCV , please bare with me. I am trying to train my network with different images (gray scaled) and for that I need to feed it using vectors of float values. (vector<float>). I searched and downloaded a database of images that were of type pgm and I need to load them as vectors.
I searched and came up with this code:

cv::Mat mat;
mat = cv::imread(fileName.toStdString().c_str());
cv::imshow(fileName.toStdString().c_str(),mat);
std::vector<float> array;
array.assign((float*)mat.datastart, (float*)mat.dataend);

The image dimensions are 19*19 (19 rows and 19 columns, verified it by rows and cols properties of mat), so the vector size should be 361, but it is 270! Is what I'm doing wrong here?

2015-10-08 00:00:27 -0600 commented question Opencv sample in Qt crashes immediately with the error 'The program has unexpectedly finished'

@StevenPuttemans: Please recover the question, Thats not the answer to my question, since if you see the question, specially the section I updated, you will notice that I had already done the suggested answer and it didn't work in qt, and the reason is explain ed at the end of the question. (I couldn't post an answer earlier, the answer to this question is know since yesterday.

2015-10-06 13:12:40 -0600 received badge  Editor (source)
2015-10-06 09:33:35 -0600 asked a question Opencv sample in Qt crashes immediately with the error 'The program has unexpectedly finished'

I tried to create a simple Opencv application in Qt and upon running, the whole application is crashed. If I comment out the opencv related codes from the project, the project runs just fine.
What I did :

Downloaded the Qt 5.5.0 VS2013 64bit version   
Downloaded the OpenCV 3.0   
Downloaded the Cmake 3.3.2

There were already prebuilt binaries in when I extracted the Opencv package, But all tutorials on the net wanted me to recompile the source codes so did I.
the package contains :

build
sources

created a new folder named mymade to hold the binaries next to the other two directories.
so it now looks like this :

 build
 mymade
 sources

Steps: Fired up CMake, specified the source folder from the extracted files and specified mymade as the output for binaries.
checked all options that had a opencv in their names, plus Qt! and configured it and subsequently generated the files.
This is the resulting contents :

enter image description here So all is done and I now need to build the binaries. I opened OpenCV.sln and compiled the release and debug binaries .
the dlls are placed inside bin directory, and the lib files are placed inside lib folder .
Now its the time to configure the Qt projects .pro file So I used the header files from build directory, and for libs I used the lib folder from mymade folder. This is the first configuration that I came up with, which compiles without any linker issues, but crashes just immediately.
the initial changes in project file :

#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = OpenCVTest
TEMPLATE = app

SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h


INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//*.lib

FORMS    += mainwindow.ui

doing this in project file as it was suggested by answers like this didnt do any good either :

#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = OpenCVTest
TEMPLATE = app

SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h


INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include

LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_core300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_highgui300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_imgcodecs300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_ml300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_objdetect300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_photo300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_shape300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_hal300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_flann300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_features2d300.lib

FORMS    += mainwindow.ui

this fails as well :

#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = OpenCVTest
TEMPLATE = app

SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h


INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include

LIBS +=-L"L://Apps_Installation_Folder//opencv//mymade//lib//Release"
LIBS += -lopencv_core300 -lopencv_highgui300 -lopencv_imgcodecs300 -lopencv_ml300 -lopencv_objdetect300 -lopencv_photo300 -lopencv_hal300 -lopencv_shape300 -lopencv_flann300 -lopencv_features2d300 ...
(more)