Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the code that allows to save the cropped image in result_img directory #7282

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

shubham-shahh
Copy link

@shubham-shahh shubham-shahh commented Jan 24, 2021

Bug Fix

  1. The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' and the code to save the image in result_img dir isn't
    updated based on the above conversion which was causing errors while recompiling the code.
    So, I've updated that, and now one can store the detected images in result_img dir. I've also updated the Readme.md based
    on that
    Fixes: How to get co-ordinates and save image of the objects #7276

Feature Addition

  1. I've added a new feature with which a user can run inference on all the images in the mentioned folder. I've also updated the readme with the information on how to use this feature.

README.md Outdated Show resolved Hide resolved
@cenit
Copy link
Collaborator

cenit commented Jan 24, 2021

I have updated your initial message and reopened initial issue. The magic token "Fixes: #issue" will close the issue if/when this PR is merged automatically

@shubham-shahh
Copy link
Author

I have updated your initial message and reopened initial issue. The magic token "Fixes: #issue" will close the issue if/when this PR is merged automatically

okay, thanks :)

README.md Outdated Show resolved Hide resolved
@cenit
Copy link
Collaborator

cenit commented Jan 25, 2021

@AlexeyAB what's your opinion on this PR? It fixes lines of code that are commented, as such they do not break nor fix anything. But, if the user was to uncomment those lines, they were broken and now ok

@shubham-shahh
Copy link
Author

  1. The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' and the code to save the image in result_img dir isn't
    updated based on the above conversion which was causing errors while recompiling the code.
    So, I've updated that, and now one can store the detected images in result_img dir. I've also updated the Readme.md based
    on that
    Fixes: How to get co-ordinates and save image of the objects #7276
  2. I've added a new feature with which a user can run inference on all the images in the mentioned folder. I've also updated the readme with the information on how to use this feature.

@cenit sir please review my recent changes, in which I've added this feature.
Thanks.

README.md Outdated
@@ -288,6 +288,8 @@ On Linux find executable file `./darknet` in the root directory, while on Window
* To calculate anchors: `darknet.exe detector calc_anchors data/obj.data -num_of_clusters 9 -width 416 -height 416`
* To check accuracy mAP@IoU=50: `darknet.exe detector map data/obj.data yolo-obj.cfg backup\yolo-obj_7000.weights`
* To check accuracy mAP@IoU=75: `darknet.exe detector map data/obj.data yolo-obj.cfg backup\yolo-obj_7000.weights -iou_thresh 0.75`
* To save the cropped image of the object detected: [`uncomment the following lines of code`](https://github.com/AlexeyAB/darknet/blob/master/src/image_opencv.cpp#L980-L996)
* To run inference on all the images in a folder: `./darknet detector test ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights -i 0 -thresh 0.25 --folder_inference ./result_img/` here `./result_img/` is the path of the folder in which the inference has to be done. the folder name can be anything, as long as it exists. After the inference the images will be moved to `./processed_files/`. To change the folder name or path, the changes cane be done [`here`](https://github.com/shubham-shahh/darknet/blob/ebc7b6f3d575402fbcd67cf214243d437f580fe1/src/detector.c#L1895).
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the readme.md

Copy link
Collaborator

@cenit cenit Feb 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As always, please use links to alexeyab's repo, without any commit id reference but pointing to the latest master trunk

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, sir, I'll do that

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sir, I've updated the link but it is broken until the PR is merged @cenit

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes of course link is broken until merged, but this is a requirement for being considered for merging!

if (lk.type == YOLO || lk.type == GAUSSIAN_YOLO || lk.type == REGION) {
l = lk;
printf(" Detection layer: %d - type = %d \n", k, l.type);
if(folder_inference==NULL){
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made changes in such a way that the original functionality is not changed by any means

@AlexeyAB
Copy link
Owner

AlexeyAB commented Feb 7, 2021

But why is
./darknet detector test ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights -i 0 -thresh 0.25 --folder_inference ./result_img/
better than
darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < data/train.txt > result.txt ?

This < data/train.txt is more flexible, since you can put either all images from folder to the data/train.txt or only some images.

@shubham-shahh
Copy link
Author

shubham-shahh commented Feb 7, 2021

But why is
./darknet detector test ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights -i 0 -thresh 0.25 --folder_inference ./result_img/
better than
darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < data/train.txt > result.txt ?

This < data/train.txt is more flexible, since you can put either all images from folder to the data/train.txt or only some images.

Hello sir, I hope you are doing well.
darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < data/train.txt > result.txt this command works well when the user knows the list of images in a folder and if no new images are added or subtracted from the folder because the program ends when the inference on all the images is done

./darknet detector test ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights -i 0 -thresh 0.25 --folder_inference ./result_img/ this command works well when new images are added constantly to a folder, as this program is non terminating and keeps looking for images in the folder. A common use case could be if new images are added to a folder from some other process and the user wants to do further inference on all the images in that folder. in this case new images are constantly added to the folder hence a user cannot make a list of it.
one more example I can think of is if a user made an API to use their custom trained YOLO model, in that case, the images uploaded by the client can be stored in a folder on which the inference is done and the results are sent back

thanks for this awesome project @AlexeyAB

@AlexeyAB
Copy link
Owner

AlexeyAB commented Feb 7, 2021

I think it is not worth to complicate the code due to the functionality that is easily achieved by these functions.

  • Linux:

ls /home/user/*.jpg > filelist.txt

./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt


  • Windows:

dir C:\images /b /s > "filelist.txt"

darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt

@shubham-shahh
Copy link
Author

shubham-shahh commented Feb 7, 2021

I think it is not worth to complicate the code due to the functionality that is easily achieved by these functions.

  • Linux:

ls /home/user/*.jpg > filelist.txt

./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt

  • Windows:

dir C:\images /b /s > "filelist.txt"

darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt

Sir, The procedure you mentioned is still terminating and the only way I can think of to make it non terminating is by creating a shell script that creates .txt files after every regular interval or to edit the code. In this approach, the user also has to make another .txt file to keep a track of images on which the inference has been done or delete the images or move them which again requires editing the code or putting that in a shell script. with this approach,
./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt has to be executed again and again which means the user has to load the model in GPU memory at regular intervals which is time-consuming and resource intensive.
Regarding the complexity of code, I've added a simple if statement if the user wants to use this functionality this block of code will execute. and if the user doesn't use the functionality the code would execute the way it used to be.

@rickkcir
Copy link

./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt

NB!

@shubham-shahh
Copy link
Author

shubham-shahh commented Oct 17, 2021

./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt

NB!

What are you trying to say? Can you please clearly describe your issue?

@rickkcir
Copy link

./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt
NB!

What are you trying to say? Can you please clearly describe your issue?

I want to get the coordinates,then I use this commad, but I found the file only saved relative coordinates,while I want to save the absolute coordinates, do you know how to realize it? thanks

@rg321
Copy link

rg321 commented Nov 2, 2021

Hi, can you try following code
in file src/image_opencv.cpp, show_img is Mat pointer.
Just crop desired portion out of Mat.

// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);

pull request created for the same
#8197

@shubham-shahh
Copy link
Author

./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt
NB!

What are you trying to say? Can you please clearly describe your issue?

I want to get the coordinates,then I use this commad, but I found the file only saved relative coordinates,while I want to save the absolute coordinates, do you know how to realize it? thanks

You can get the absolute co ordinates since you already know the original image size

@shubham-shahh
Copy link
Author

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.

// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);

pull request created for the same #8197

Can you clearly mention what exactly you're expecting?

Thanks

Copy link
Author

@shubham-shahh shubham-shahh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cenit what does this commit do?

@rg321
Copy link

rg321 commented Nov 16, 2021

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.
// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);
pull request created for the same #8197

Can you clearly mention what exactly you're expecting?

Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -:
cv::Mat copy_image = (*show_img)(rect)
rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -:
cv::imwrite(image_name, copy_image)
Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

// if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels);
// cvCopy(show_img, copy_img, 0);
// if(copy_img == NULL) copy_img = cvCreateImage(cvSize(ipltypeimg->width, ipltypeimg->height), ipltypeimg->depth, ipltypeimg->nChannels);
// cvCopy(ipltypeimg, copy_img, 0);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is solved here @rg321

@shubham-shahh
Copy link
Author

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.
// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);
pull request created for the same #8197

Can you clearly mention what exactly you're expecting?
Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.
// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);
pull request created for the same #8197

Can you clearly mention what exactly you're expecting?
Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

H

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.
// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);
pull request created for the same #8197

Can you clearly mention what exactly you're expecting?
Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, this PR also implements some more features along with solving that bug. That bug is simply solved by converting the image to ipltype, I tagged you where I have done that conversion. Rest changes of this PR are made to implement several other features

Thanks

@rg321
Copy link

rg321 commented Nov 24, 2021

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.
// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);
pull request created for the same #8197

Can you clearly mention what exactly you're expecting?
Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.
// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);
pull request created for the same #8197

Can you clearly mention what exactly you're expecting?
Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

H

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.
// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);
pull request created for the same #8197

Can you clearly mention what exactly you're expecting?
Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, this PR also implements some more features along with solving that bug. That bug is simply solved by converting the image to ipltype, I tagged you where I have done that conversion. Rest changes of this PR are made to implement several other features

Thanks

In that case, you may either exactly mention in title of this pull request or you may want to create different pull request for the bug and a different one for features implemented. That would provide more clarity to your pull request. If possible, provide appropriate title to your pull request, what bug it solves or what feature it implements and add changes necessary for that only in that particular pull request. Else, as I mentioned above, for the problem mentioned in the title, my changes are good enough.

@shubham-shahh
Copy link
Author

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.
// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);
pull request created for the same #8197

Can you clearly mention what exactly you're expecting?
Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.
// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);
pull request created for the same #8197

Can you clearly mention what exactly you're expecting?
Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

H

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.
// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);
pull request created for the same #8197

Can you clearly mention what exactly you're expecting?
Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

i

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.
// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);
pull request created for the same #8197

Can you clearly mention what exactly you're expecting?
Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.
// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);
pull request created for the same #8197

Can you clearly mention what exactly you're expecting?
Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

H

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.
// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);
pull request created for the same #8197

Can you clearly mention what exactly you're expecting?
Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, this PR also implements some more features along with solving that bug. That bug is simply solved by converting the image to ipltype, I tagged you where I have done that conversion. Rest changes of this PR are made to implement several other features
Thanks

In that case, you may either exactly mention in title of this pull request or you may want to create different pull request for the bug and a different one for features implemented. That would provide more clarity to your pull request. If possible, provide appropriate title to your pull request, what bug it solves or what feature it implements and add changes necessary for that only in that particular pull request. Else, as I mentioned above, for the problem mentioned in the title, my changes are good enough.

Hi,
you can check the description, I have clearly mentioned what bug it solves and which feature it implements

thanks

@@ -8,6 +8,7 @@
#include "box.h"
#include "demo.h"
#include "option_list.h"
#include <dirent.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is using dirent.h and code that is not cross-compatible, so is unacceptable as is

Copy link
Author

@shubham-shahh shubham-shahh Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add alternatives to dirent @cenit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please tag what part of the code which is causing issue? I will work on it. plus this is a really old PR it needs rebasing as well

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rebased it on latest master for you before commenting the issue

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just rewrite the code in this file avoiding dirent.h inclusion (not available on windows)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, thanks for pointing out the issues, I'll work on them

Comment on lines +1785 to +1786
DIR *folder;
struct dirent *entry;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two lines, for example, depend on dirent.h being included, which is incompatible with our aim of being 100% windows compatible

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I noted it, I'll apply required changes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's your opinion for Boost filesystem? I don't have much experience in building projects in windows. all your help is appreciated

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you can use std::filesystem it would be much better, so that we can avoid depending on another external lib

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll look into it
thanks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @cenit I was planning to fix this PR, I just wanted to know if there are any other changes to make other than filesystem?

@shubham-shahh
Copy link
Author

Hi @cenit looks like you've fixed the issue related to building in windows, can we merge this PR into master?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to get co-ordinates and save image of the objects
5 participants